Not (Really) Part Of The Build (Yet). Make gfxSkipCharsIterator::IsOriginalCharSkipped operate correctly when the iterator is currently pointed at a zero-length run.

This commit is contained in:
roc+@cs.cmu.edu 2007-05-14 20:09:16 -07:00
parent e74bb303b6
commit b9c2535e4d

View File

@ -184,15 +184,25 @@ gfxSkipCharsIterator::IsOriginalCharSkipped(PRInt32* aRunLength) const
return mSkipChars->mCharCount == PRUint32(mOriginalStringOffset); return mSkipChars->mCharCount == PRUint32(mOriginalStringOffset);
} }
PRUint32 listPrefixLength = mListPrefixLength;
// figure out which segment we're in // figure out which segment we're in
PRUint32 currentRunLength = mSkipChars->mList[mListPrefixLength]; PRUint32 currentRunLength = mSkipChars->mList[listPrefixLength];
// Zero-length list entries are possible. Advance until mListPrefixLength
// is pointing to a run with real characters (or we're at the end of the
// string).
while (currentRunLength == 0 && listPrefixLength < mSkipChars->mListLength - 1) {
++listPrefixLength;
// This does not break the iterator's invariant because no skipped
// or kept characters are being added
currentRunLength = mSkipChars->mList[listPrefixLength];
}
NS_ASSERTION(PRUint32(mOriginalStringOffset) >= mListPrefixCharCount, NS_ASSERTION(PRUint32(mOriginalStringOffset) >= mListPrefixCharCount,
"Invariant violation"); "Invariant violation");
PRUint32 offsetIntoCurrentRun = PRUint32 offsetIntoCurrentRun =
PRUint32(mOriginalStringOffset) - mListPrefixCharCount; PRUint32(mOriginalStringOffset) - mListPrefixCharCount;
if (mListPrefixLength >= mSkipChars->mListLength - 1 && if (listPrefixLength >= mSkipChars->mListLength - 1 &&
offsetIntoCurrentRun >= currentRunLength) { offsetIntoCurrentRun >= currentRunLength) {
NS_ASSERTION(mListPrefixLength == mSkipChars->mListLength - 1 && NS_ASSERTION(listPrefixLength == mSkipChars->mListLength - 1 &&
offsetIntoCurrentRun == currentRunLength, offsetIntoCurrentRun == currentRunLength,
"Overran end of string"); "Overran end of string");
// We're at the end of the string // We're at the end of the string
@ -202,13 +212,13 @@ gfxSkipCharsIterator::IsOriginalCharSkipped(PRInt32* aRunLength) const
return PR_TRUE; return PR_TRUE;
} }
PRBool isSkipped = !IsKeepEntry(mListPrefixLength); PRBool isSkipped = !IsKeepEntry(listPrefixLength);
if (aRunLength) { if (aRunLength) {
// Long runs of all-skipped or all-kept characters will be encoded as // Long runs of all-skipped or all-kept characters will be encoded as
// sequences of 255, 0, 255, 0 etc. Compute the maximum run length by skipping // sequences of 255, 0, 255, 0 etc. Compute the maximum run length by skipping
// over zero entries. // over zero entries.
PRUint32 runLength = currentRunLength - offsetIntoCurrentRun; PRUint32 runLength = currentRunLength - offsetIntoCurrentRun;
for (PRUint32 i = mListPrefixLength + 2; i < mSkipChars->mListLength; i += 2) { for (PRUint32 i = listPrefixLength + 2; i < mSkipChars->mListLength; i += 2) {
if (mSkipChars->mList[i - 1] != 0) if (mSkipChars->mList[i - 1] != 0)
break; break;
runLength += mSkipChars->mList[i]; runLength += mSkipChars->mList[i];