From 0d762b00de43e9c73a77969afb52a68f1974c54e Mon Sep 17 00:00:00 2001 From: jvr Date: Sat, 4 May 2002 22:03:05 +0000 Subject: [PATCH] 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 --- Lib/fontTools/ttLib/tables/_p_o_s_t.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Lib/fontTools/ttLib/tables/_p_o_s_t.py b/Lib/fontTools/ttLib/tables/_p_o_s_t.py index 203be8241..32fccb910 100644 --- a/Lib/fontTools/ttLib/tables/_p_o_s_t.py +++ b/Lib/fontTools/ttLib/tables/_p_o_s_t.py @@ -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)