Bug 1385159 - Use AutoArray to prevent buffer allocation in DrawTargetSkia::DrawGlyphs.
Replace std::vector by AutoArray to prevent heap allocation.
I set default size of these array by 512, since in practice, most strings are
shorter than 512.
MozReview-Commit-ID: 4xVOaEHkJVi
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -1438,28 +1438,24 @@ DrawTargetSkia::DrawGlyphs(ScaledFont* a
break;
}
#endif
default:
break;
}
paint.mPaint.setSubpixelText(useSubpixelText);
- AutoTArray<uint16_t, 10> indices;
- AutoTArray<SkPoint, 10> offsets;
- if (!indices.SetLength(aBuffer.mNumGlyphs, fallible) ||
- !offsets.SetLength(aBuffer.mNumGlyphs, fallible)) {
- // Run out of memory.
- return;
- }
+ AutoTArray<uint16_t, 512> indices;
+ AutoTArray<SkPoint, 512> offsets;
for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
- indices[i] = aBuffer.mGlyphs[i].mIndex;
- offsets[i].fX = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x);
- offsets[i].fY = SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y);
+ indices.AppendElement(aBuffer.mGlyphs[i].mIndex);
+ offsets.AppendElement(
+ SkPoint::Make(SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.x),
+ SkFloatToScalar(aBuffer.mGlyphs[i].mPosition.y)));
}
mCanvas->drawPosText(indices.Elements(), aBuffer.mNumGlyphs*2, offsets.Elements(), paint.mPaint);
}
void
DrawTargetSkia::FillGlyphs(ScaledFont* aFont,
const GlyphBuffer& aBuffer,