提交 56c7fb8c 编写于 作者: B Behdad Esfahbod

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
上级 6da7796c
......@@ -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<int> 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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册