Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-08-16 07:28:10 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-08-16 07:35:38 +0300
commitc0016a8581f3124d34dc8cf0a2a5c3374e72356a (patch)
tree36796183f4a3101f4e3e45c590689c092fc8269c /source/blender/blenfont/intern
parent4300050e20a7fa5c06a990c1f7df3792b7fed656 (diff)
BLF: avoid unnecessary lookups in blf_kerning_cache_new
blf_kerning_cache_new was performing many unnecessary hash lookups, calling blf_glyph_search 32768 times. Use a lookup table to reduce this to the number of ASCII characters (128 calls).
Diffstat (limited to 'source/blender/blenfont/intern')
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index a2571860c94..c5abc5982e8 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -72,34 +72,36 @@ KerningCacheBLF *blf_kerning_cache_find(FontBLF *font)
/* Create a new glyph cache for the current kerning mode. */
KerningCacheBLF *blf_kerning_cache_new(FontBLF *font, GlyphCacheBLF *gc)
{
- KerningCacheBLF *kc;
-
- kc = (KerningCacheBLF *)MEM_callocN(sizeof(KerningCacheBLF), "blf_kerning_cache_new");
+ KerningCacheBLF *kc = MEM_mallocN(sizeof(KerningCacheBLF), __func__);
kc->next = NULL;
kc->prev = NULL;
kc->mode = font->kerning_mode;
- unsigned int i, j;
- for (i = 0; i < KERNING_CACHE_TABLE_SIZE; i++) {
- for (j = 0; j < KERNING_CACHE_TABLE_SIZE; j++) {
- GlyphBLF *g = blf_glyph_search(gc, i);
- if (!g) {
- FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
- g = blf_glyph_add(font, gc, glyph_index, i);
+ GlyphBLF *g_table[KERNING_CACHE_TABLE_SIZE];
+ for (uint i = 0; i < KERNING_CACHE_TABLE_SIZE; i++) {
+ GlyphBLF *g = blf_glyph_search(gc, i);
+ if (UNLIKELY(g == NULL)) {
+ FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
+ g = blf_glyph_add(font, gc, glyph_index, i);
+ }
+ g_table[i] = g;
+ }
+
+ memset(kc->ascii_table, 0, sizeof(kc->ascii_table));
+ for (uint i = 0; i < KERNING_CACHE_TABLE_SIZE; i++) {
+ GlyphBLF *g = g_table[i];
+ if (g == NULL) {
+ continue;
+ }
+ for (uint j = 0; j < KERNING_CACHE_TABLE_SIZE; j++) {
+ GlyphBLF *g_prev = g_table[j];
+ if (g_prev == NULL) {
+ continue;
}
- /* Can fail on certain fonts */
- GlyphBLF *g_prev = blf_glyph_search(gc, j);
-
- FT_Vector delta = {
- .x = 0,
- .y = 0,
- };
- if (g && g_prev && FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) {
+ FT_Vector delta;
+ if (FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) {
kc->ascii_table[i][j] = (int)delta.x >> 6;
}
- else {
- kc->ascii_table[i][j] = 0;
- }
}
}