use dict for extraNames lookups, getting rid of quadratic behavior
git-svn-id: svn://svn.code.sf.net/p/fonttools/code/trunk@200 4cde692c-a291-49d1-8350-778aa11640f8
This commit is contained in:
parent
25ccb9c346
commit
0d762b00de
@ -123,23 +123,28 @@ class table__p_o_s_t(DefaultTable.DefaultTable):
|
||||
glyphOrder = ttFont.getGlyphOrder()
|
||||
assert len(glyphOrder) == numGlyphs
|
||||
indices = array.array("H")
|
||||
extraDict = {}
|
||||
extraNames = self.extraNames
|
||||
for i in range(len(extraNames)):
|
||||
extraDict[extraNames[i]] = i
|
||||
for glyphID in range(numGlyphs):
|
||||
glyphName = glyphOrder[glyphID]
|
||||
if self.mapping.has_key(glyphName):
|
||||
psName = self.mapping[glyphName]
|
||||
else:
|
||||
psName = glyphName
|
||||
if psName in self.extraNames:
|
||||
index = 258 + self.extraNames.index(psName)
|
||||
if extraDict.has_key(psName):
|
||||
index = 258 + extraDict[psName]
|
||||
elif psName in standardGlyphOrder:
|
||||
index = standardGlyphOrder.index(psName)
|
||||
else:
|
||||
index = 258 + len(self.extraNames)
|
||||
self.extraNames.append(psName)
|
||||
index = 258 + len(extraNames)
|
||||
extraDict[psName] = len(extraNames)
|
||||
extraNames.append(psName)
|
||||
indices.append(index)
|
||||
if ttLib.endian <> "big":
|
||||
indices.byteswap()
|
||||
return struct.pack(">H", numGlyphs) + indices.tostring() + packPStrings(self.extraNames)
|
||||
return struct.pack(">H", numGlyphs) + indices.tostring() + packPStrings(extraNames)
|
||||
|
||||
def toXML(self, writer, ttFont):
|
||||
formatstring, names, fixes = sstruct.getformat(postFormat)
|
||||
|
Loading…
x
Reference in New Issue
Block a user