[use-table] Port to using packtab

Saves around 9kb.
This commit is contained in:
Behdad Esfahbod 2022-07-13 12:15:01 -06:00
parent 0fcd1decb7
commit 015aecfcdd
3 changed files with 263 additions and 1492 deletions

View File

@ -478,64 +478,15 @@ for k,v in sorted(use_positions.items()):
print ("#define %s USE(%s)" % (tag, tag))
print ('#pragma GCC diagnostic pop')
print ("")
print ("static const uint8_t use_table[] = {")
for u in uu:
if u <= last:
continue
if use_data[u][0] == 'O':
continue
block = use_data[u][1]
start = u//8*8
end = start+1
while end in uu and block == use_data[end][1]:
end += 1
end = (end-1)//8*8 + 7
if start != last + 1:
if start - last <= 1+16*3:
print_block (None, last+1, start-1, use_data)
else:
if last >= 0:
ends.append (last + 1)
offset += ends[-1] - starts[-1]
print ()
print ()
print ("#define use_offset_0x%04xu %d" % (start, offset))
starts.append (start)
import packTab
data = {u:v[0] for u,v in use_data.items()}
code = packTab.Code('hb_use')
sol = packTab.pack_table(data, compression=5, default='O')
sol.genCode(code, f'get_category')
code.print_c(linkage='static inline')
print_block (block, start, end, use_data)
last = end
ends.append (last + 1)
offset += ends[-1] - starts[-1]
print ()
print ()
occupancy = used * 100. / total
page_bits = 12
print ("}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy))
print ()
print ("static inline uint8_t")
print ("hb_use_get_category (hb_glyph_info_t info)")
print ("{")
print (" hb_codepoint_t u = info.codepoint;")
print (" switch (u >> %d)" % page_bits)
print (" {")
pages = set([u>>page_bits for u in starts+ends])
for p in sorted(pages):
print (" case 0x%0Xu:" % p)
for (start,end) in zip (starts, ends):
if p not in [start>>page_bits, end>>page_bits]: continue
offset = "use_offset_0x%04xu" % start
print (" if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return use_table[u - 0x%04Xu + %s];" % (start, end-1, start, offset))
print (" break;")
print ("")
print (" default:")
print (" break;")
print (" }")
print (" if (_hb_glyph_info_get_general_category (&info) == HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED)")
print (" return WJ;")
print (" return O;")
print ("}")
print ()
for k in sorted(use_mapping.keys()):
if k in use_positions and use_positions[k]: continue
@ -549,7 +500,3 @@ print ()
print ()
print ("#endif /* HB_OT_SHAPER_USE_TABLE_HH */")
print ("/* == End of generated table == */")
# Maintain at least 50% occupancy in the table */
if occupancy < 50:
raise Exception ("Table too sparse, please investigate: ", occupancy)

File diff suppressed because it is too large Load Diff

View File

@ -206,7 +206,7 @@ setup_masks_use (const hb_ot_shape_plan_t *plan,
unsigned int count = buffer->len;
hb_glyph_info_t *info = buffer->info;
for (unsigned int i = 0; i < count; i++)
info[i].use_category() = hb_use_get_category (info[i]);
info[i].use_category() = hb_use_get_category (info[i].codepoint);
}
static void