[subset/cff1] Don't allocate memory for retaingid holes

40% speedup in BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/retaingids/10
benchmark.
pull/4264/head
Behdad Esfahbod 1 year ago
parent b5792f117a
commit 054f966a57
  1. 2
      src/hb-cff-interp-common.hh
  2. 3
      src/hb-static.cc
  3. 14
      src/hb-subset-cff-common.hh
  4. 10
      src/hb-vector.hh

@ -26,6 +26,8 @@
#ifndef HB_CFF_INTERP_COMMON_HH
#define HB_CFF_INTERP_COMMON_HH
extern HB_INTERNAL const unsigned char *endchar_str;
namespace CFF {
using namespace OT;

@ -31,6 +31,7 @@
#include "hb-aat-layout-common.hh"
#include "hb-aat-layout-feat-table.hh"
#include "hb-cff-interp-common.hh"
#include "hb-ot-layout-common.hh"
#include "hb-ot-cmap-table.hh"
#include "OT/Color/COLR/COLR.hh"
@ -58,6 +59,8 @@ DEFINE_NULL_NAMESPACE_BYTES (AAT, Lookup) = {0xFF,0xFF};
/* hb_map_t */
const hb_codepoint_t minus_1 = -1;
static const unsigned char static_endchar_str[] = {OpCode_endchar};
const unsigned char *endchar_str = static_endchar_str;
/* hb_face_t */

@ -809,7 +809,12 @@ struct subr_subsetter_t
if (endchar_op != OpCode_Invalid)
for (; last < gid; last++)
buffArray.arrayZ[last].push (endchar_op);
{
// Hack to point vector to static string.
auto &b = buffArray.arrayZ[last];
b.length = 1;
b.arrayZ = const_cast<unsigned char *>(endchar_str);
}
last++; // Skip over gid
unsigned int fd = acc.fdSelect->get_fd (old_glyph);
@ -820,7 +825,12 @@ struct subr_subsetter_t
}
if (endchar_op != OpCode_Invalid)
for (; last < num_glyphs; last++)
buffArray.arrayZ[last].push (endchar_op);
{
// Hack to point vector to static string.
auto &b = buffArray.arrayZ[last];
b.length = 1;
b.arrayZ = const_cast<unsigned char *>(endchar_str);
}
return true;
}

@ -102,8 +102,14 @@ struct hb_vector_t
void fini ()
{
shrink_vector (0);
hb_free (arrayZ);
/* We allow a hack to make the vector point to a foriegn array
* by the user. In that case length/arrayZ are non-zero but
* allocated is zero. Don't free anything. */
if (!allocated)
{
shrink_vector (0);
hb_free (arrayZ);
}
init ();
}

Loading…
Cancel
Save