Create subReaders lazily

Should improve memory usage
This commit is contained in:
Behdad Esfahbod 2013-11-24 18:28:20 -05:00
parent e84f9fd1b5
commit c491f45eff
2 changed files with 16 additions and 17 deletions

View File

@ -585,8 +585,9 @@ class BaseTable(object):
def ensureDecompiled(self): def ensureDecompiled(self):
if self.compileStatus != 1: if self.compileStatus != 1:
return return
self.decompile(self.reader, self.font) subReader = self.reader.getSubReader(self.offset)
del self.reader, self.font self.decompile(subReader, self.font)
del self.reader, self.font, self.offset
def preCompile(self): def preCompile(self):
pass # used only by the LookupList class pass # used only by the LookupList class

View File

@ -183,14 +183,13 @@ class Table(Struct):
print "*** Warning: offset is not 0, yet suspiciously low (%s). table: %s" \ print "*** Warning: offset is not 0, yet suspiciously low (%s). table: %s" \
% (offset, self.tableClass.__name__) % (offset, self.tableClass.__name__)
return None return None
subReader = reader.getSubReader(offset)
table = self.tableClass() table = self.tableClass()
if lazy: table.reader = reader
table.reader = subReader table.offset = offset
table.font = font table.font = font
table.compileStatus = 1 table.compileStatus = 1
else: if not lazy:
table.decompile(subReader, font) table.ensureDecompiled()
return table return table
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):
@ -222,15 +221,14 @@ class ExtSubTable(Table):
offset = reader.readULong() offset = reader.readULong()
if offset == 0: if offset == 0:
return None return None
subReader = reader.getSubReader(offset)
table = self.tableClass() table = self.tableClass()
table.start = subReader.offset table.start = reader.offset + offset
if lazy: table.reader = reader
table.reader = subReader table.offset = offset
table.font = font table.font = font
table.compileStatus = 1 table.compileStatus = 1
else: if not lazy:
table.decompile(subReader, font) table.ensureDecompiled()
return table return table
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):