Commit 521627d0 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Avoid redundant lookups in glyphs cache.

This CL has no behavior change.

It is a simple optimisation that avoid doing two lookups in the map.
The iterator returns by map::find is able to do both queries.

R=robliao@chromium.org, asvitkine@chromium.org

Change-Id: If6dc1c90914e0f5f7c6616d47f7a0325cfda93da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872308Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708375}
parent f4bc7306
......@@ -89,11 +89,15 @@ hb_bool_t GetGlyph(hb_font_t* font,
FontData* font_data = reinterpret_cast<FontData*>(data);
GlyphCache* cache = font_data->glyph_cache_;
bool exists = cache->count(unicode) != 0;
if (!exists)
(*cache)[unicode] = font_data->font_.unicharToGlyph(unicode);
GlyphCache::iterator iter = cache->find(unicode);
if (iter == cache->end()) {
auto result = cache->insert(
std::make_pair(unicode, font_data->font_.unicharToGlyph(unicode)));
DCHECK(result.second);
iter = result.first;
}
*glyph = (*cache)[unicode];
*glyph = iter->second;
return !!*glyph;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment