Bug 371839. Assertions that scan all continuations should bail out if the continuation chain is too long, so they don't add O(N) to algorithmic complexity. r=bzbarsky

This commit is contained in:
Robert O'Callahan 2009-07-10 14:03:03 +12:00
parent c862b4f8f6
commit 301eb1e0b2
2 changed files with 19 additions and 4 deletions

View File

@ -131,20 +131,26 @@ nsIFrame* nsSplittableFrame::GetLastContinuation() const
#ifdef DEBUG
PRBool nsSplittableFrame::IsInPrevContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
{
while (aFrame1) {
PRInt32 iterations = 0;
while (aFrame1 && iterations < 10) {
// Bail out after 10 iterations so we don't bog down debug builds too much
if (aFrame1 == aFrame2)
return PR_TRUE;
aFrame1 = aFrame1->GetPrevContinuation();
++iterations;
}
return PR_FALSE;
}
PRBool nsSplittableFrame::IsInNextContinuationChain(nsIFrame* aFrame1, nsIFrame* aFrame2)
{
while (aFrame1) {
PRInt32 iterations = 0;
while (aFrame1 && iterations < 10) {
// Bail out after 10 iterations so we don't bog down debug builds too much
if (aFrame1 == aFrame2)
return PR_TRUE;
aFrame1 = aFrame1->GetNextContinuation();
++iterations;
}
return PR_FALSE;
}

View File

@ -5958,10 +5958,19 @@ nsTextFrame::SetLength(PRInt32 aLength)
f = static_cast<nsTextFrame*>(f->GetNextInFlow());
}
#ifdef DEBUG
f = static_cast<nsTextFrame*>(this->GetFirstContinuation());
while (f) {
f = this;
PRInt32 iterations = 0;
while (f && iterations < 10) {
f->GetContentLength(); // Assert if negative length
f = static_cast<nsTextFrame*>(f->GetNextContinuation());
++iterations;
}
f = this;
iterations = 0;
while (f && iterations < 10) {
f->GetContentLength(); // Assert if negative length
f = static_cast<nsTextFrame*>(f->GetPrevContinuation());
++iterations;
}
#endif
}