Change cmap-based duplicate-name resolution from n^2 to linear time

Similar to 85be2e0a9773acec3c6d14c345b1fd94ab3aa5c3, though much
harder to hit.
This commit is contained in:
Behdad Esfahbod 2014-06-02 18:09:47 -04:00
parent 4ff0d4b192
commit 9f23ee4cc8

View File

@ -506,12 +506,11 @@ class TTFont(object):
# create uni<CODE> name
glyphName = "uni%04X" % unicode
tempName = glyphName
n = 1
while tempName in allNames:
tempName = glyphName + "#" + repr(n)
n = n + 1
n = allNames.get(tempName, 0)
if n:
tempName = glyphName + "#" + str(n)
glyphOrder[i] = tempName
allNames[tempName] = 1
allNames[tempName] = n + 1
# Delete the temporary cmap table from the cache, so it can
# be parsed again with the right names.
del self.tables['cmap']