You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One thing that may help with the memory footprint is to recycle duplicate ClassDef objects. As it is now, every class is fully expanded at all times. This makes sense given that I was trying to keep the code simple instead of worrying about memory when I write this library. Anyway, here's a quick sketch:
importhashlibclass_ClassDefRegistry(object):
def__init__(self):
self._classes= {}
def_makeIdentifier(self, mapping):
identifier= []
forname, valueinsorted(mapping.items()):
identifier.append("%s %d"% (name, value))
identifier="\n".join(identifier)
identifier=hashlib.md5(identifier) # this may be over-engineeringreturnidentifierdefstore(self, mapping):
identifier=self._makeIdentifier(mapping)
self._classes[identifier] =mappingreturnidentifierdef__getitem__(self, identifier):
returnself._classes[identifier]
classClassDef(object):
__slots__= ["_identifier", "_classDefRegistry", "_map", "ClassFormat", "Glyphs"]
def__init__(self, classDefRegistry):
self._classDefRegistry=classDefRegistryself.ClassFormat=NonedefloadFromFontTools(self, classDef):
self.ClassFormat=classDef.Formatself._identifier=self._classDefRegistry.store(dict(classDef.classDefs))
returnselfdef__getitem__(self, glyphName):
returnself.Glyphs.get(glyphName, 0)
def_get_Glyphs(self):
returnself._classDefRegistry[self._identifier]
Glyphs=property(_get_Glyphs, doc="This is for reference only. Not for use in processing.")
# ----# Test# ----class_Dummy(object):
def__init__(self):
self.Format=0self.classDefs= {}
test=_Dummy()
letters="abcdefghijklmnopqrstuvwxyz"foriinrange(26):
forjinrange(1, 11):
name=letters[i] *jvalue=len(test.classDefs)
test.classDefs[name] =valueregistry=_ClassDefRegistry()
classDef=ClassDef(registry)
classDef.loadFromFontTools(test)
printclassDef.GlyphsprintclassDef["mmm"]
This would require some significant structural engineering so that the global registry is passed around as needed.
The text was updated successfully, but these errors were encountered:
One thing that may help with the memory footprint is to recycle duplicate ClassDef objects. As it is now, every class is fully expanded at all times. This makes sense given that I was trying to keep the code simple instead of worrying about memory when I write this library. Anyway, here's a quick sketch:
This would require some significant structural engineering so that the global registry is passed around as needed.
The text was updated successfully, but these errors were encountered: