mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-13 08:42:59 +00:00
[VARC/MultiVarStore] Reduce malloc pressure more
This commit is contained in:
parent
6938ee0342
commit
97a5c52af4
2 changed files with 18 additions and 6 deletions
|
@ -381,7 +381,8 @@ VARC::get_path_at (hb_font_t *font,
|
|||
|
||||
hb_ubytes_t record = (this+glyphRecords)[idx];
|
||||
|
||||
VarRegionList::cache_t *cache = coords ? (this+varStore).create_cache () : nullptr;
|
||||
float static_cache[128];
|
||||
VarRegionList::cache_t *cache = (this+varStore).create_cache (hb_array (static_cache));
|
||||
|
||||
transform.scale (font->x_multf, font->y_multf);
|
||||
|
||||
|
@ -392,7 +393,7 @@ VARC::get_path_at (hb_font_t *font,
|
|||
scratch,
|
||||
cache);
|
||||
|
||||
(this+varStore).destroy_cache (cache);
|
||||
(this+varStore).destroy_cache (cache, hb_array (static_cache));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3440,7 +3440,7 @@ struct MultiItemVariationStore
|
|||
{
|
||||
using cache_t = SparseVarRegionList::cache_t;
|
||||
|
||||
cache_t *create_cache () const
|
||||
cache_t *create_cache (hb_array_t<float> static_cache = hb_array_t<float> ()) const
|
||||
{
|
||||
#ifdef HB_NO_VAR
|
||||
return nullptr;
|
||||
|
@ -3448,8 +3448,14 @@ struct MultiItemVariationStore
|
|||
auto &r = this+regions;
|
||||
unsigned count = r.regions.len;
|
||||
|
||||
float *cache = (float *) hb_malloc (sizeof (float) * count);
|
||||
if (unlikely (!cache)) return nullptr;
|
||||
float *cache;
|
||||
if (count <= static_cache.length)
|
||||
cache = static_cache.arrayZ;
|
||||
else
|
||||
{
|
||||
cache = (float *) hb_malloc (sizeof (float) * count);
|
||||
if (unlikely (!cache)) return nullptr;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
cache[i] = REGION_CACHE_ITEM_CACHE_INVALID;
|
||||
|
@ -3457,7 +3463,12 @@ struct MultiItemVariationStore
|
|||
return cache;
|
||||
}
|
||||
|
||||
static void destroy_cache (cache_t *cache) { hb_free (cache); }
|
||||
static void destroy_cache (cache_t *cache,
|
||||
hb_array_t<float> static_cache = hb_array_t<float> ())
|
||||
{
|
||||
if (cache != static_cache.arrayZ)
|
||||
hb_free (cache);
|
||||
}
|
||||
|
||||
private:
|
||||
void get_delta (unsigned int outer, unsigned int inner,
|
||||
|
|
Loading…
Add table
Reference in a new issue