Coalesce neighboring symbol maps for better lookup performance

This commit is contained in:
Kovid Goyal
2019-11-12 20:05:48 +05:30
parent 83932c8099
commit a649eb2a48
2 changed files with 29 additions and 2 deletions

View File

@@ -25,8 +25,29 @@ else:
current_faces = None
def coalesce_symbol_maps(maps):
if not maps:
return maps
items = tuple((k, maps[k]) for k in sorted(maps))
ans = [items[0]]
def merge(prev_item, item):
s, e = item[0]
pe = prev_item[0][1]
ans[-1] = ((prev_item[0][0], max(pe, e)), prev_item[1])
for item in items[1:]:
current_item = ans[-1]
if current_item[1] != item[1] or item[0][0] > current_item[0][1] + 1:
ans.append(item)
else:
merge(current_item, item)
return dict(ans)
def create_symbol_map(opts):
val = opts.symbol_map
val = coalesce_symbol_maps(opts.symbol_map)
family_map = {}
count = 0
for family in val.values():