From 11c8920a3fc1c5895e777f71c822501367eef69c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 21 Aug 2014 19:14:14 -0400 Subject: [PATCH] Allocate font vector on stack This reduces another allocation (last one?) we were doing when fulfilling shaping requests from the cache. Bug: 17111260 Change-Id: Ieb8ae1ccfcaacedb257e1e9263777f10623aaf98 --- engine/src/flutter/libs/minikin/Layout.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 46819d64e4..c3d4c13e86 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -760,11 +760,16 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t } void Layout::appendLayout(Layout* src, size_t start) { - // Note: size==1 is by far most common, should have specialized vector for this - std::vector fontMap; + int fontMapStack[16]; + int* fontMap; + if (src->mFaces.size() < sizeof(fontMapStack) / sizeof(fontMapStack[0])) { + fontMap = fontMapStack; + } else { + fontMap = new int[src->mFaces.size()]; + } for (size_t i = 0; i < src->mFaces.size(); i++) { int font_ix = findFace(src->mFaces[i], NULL); - fontMap.push_back(font_ix); + fontMap[i] = font_ix; } int x0 = mAdvance; for (size_t i = 0; i < src->mGlyphs.size(); i++) { @@ -783,6 +788,10 @@ void Layout::appendLayout(Layout* src, size_t start) { srcBounds.offset(x0, 0); mBounds.join(srcBounds); mAdvance += src->mAdvance; + + if (fontMap != fontMapStack) { + delete[] fontMap; + } } void Layout::draw(Bitmap* surface, int x0, int y0, float size) const {