bug 763873 - avoid repeatedly accessing aRanges.Length() within ComputeRanges. r=jdaggett

This commit is contained in:
Jonathan Kew 2012-06-26 09:51:37 +01:00
Родитель df9d145497
Коммит 744969c088
1 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -3411,6 +3411,8 @@ gfxFontGroup::InitTextRun(gfxContext *aContext,
const T *aString,
PRUint32 aLength)
{
NS_ASSERTION(aLength > 0, "don't call InitTextRun for a zero-length run");
// we need to do numeral processing even on 8-bit text,
// in case we're converting Western to Hindi/Arabic digits
PRInt32 numOption = gfxPlatform::GetPlatform()->GetBidiNumeralOption();
@ -3527,6 +3529,9 @@ gfxFontGroup::InitScriptRun(gfxContext *aContext,
PRUint32 aScriptRunEnd,
PRInt32 aRunScript)
{
NS_ASSERTION(aScriptRunEnd > aScriptRunStart,
"don't call InitScriptRun for a zero-length run");
gfxFont *mainFont = GetFontAt(0);
PRUint32 runStart = aScriptRunStart;
@ -3763,14 +3768,12 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
const T *aString, PRUint32 aLength,
PRInt32 aRunScript)
{
aRanges.Clear();
if (aLength == 0) {
return;
}
NS_ASSERTION(aRanges.Length() == 0, "aRanges must be initially empty");
NS_ASSERTION(aLength > 0, "don't call ComputeRanges for zero-length text");
PRUint32 prevCh = 0;
PRUint8 matchType = 0;
PRInt32 lastRangeIndex = -1;
// initialize prevFont to the group's primary font, so that this will be
// used for string-initial control chars, etc rather than risk hitting font
@ -3803,18 +3806,20 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
prevCh = ch;
if (aRanges.Length() == 0) {
if (lastRangeIndex == -1) {
// first char ==> make a new range
aRanges.AppendElement(gfxTextRange(0, 1, font, matchType));
lastRangeIndex++;
prevFont = font;
} else {
// if font has changed, make a new range
gfxTextRange& prevRange = aRanges[aRanges.Length() - 1];
gfxTextRange& prevRange = aRanges[lastRangeIndex];
if (prevRange.font != font || prevRange.matchType != matchType) {
// close out the previous range
prevRange.end = origI;
aRanges.AppendElement(gfxTextRange(origI, i + 1,
font, matchType));
lastRangeIndex++;
// update prevFont for the next match, *unless* we switched
// fonts on a ZWJ, in which case propagating the changed font
@ -3827,7 +3832,8 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
}
}
}
aRanges[aRanges.Length() - 1].end = aLength;
aRanges[lastRangeIndex].end = aLength;
}
gfxUserFontSet*