[glyf] Use memoryview() in decompile for larger glyphs

This commit is contained in:
Behdad Esfahbod 2021-04-07 13:15:26 -06:00
parent 4ff6b3390e
commit e328ee0254

View File

@ -689,6 +689,10 @@ class Glyph(object):
len(data)) len(data))
def decompileCoordinates(self, data): def decompileCoordinates(self, data):
# Slicing small bytes() object is faster than slicing memoryview;
# Cutoff empirically determined.
if len(data) >= 128:
data = memoryview(data)
endPtsOfContours = array.array("h") endPtsOfContours = array.array("h")
endPtsOfContours.frombytes(data[:2*self.numberOfContours]) endPtsOfContours.frombytes(data[:2*self.numberOfContours])
if sys.byteorder != "big": endPtsOfContours.byteswap() if sys.byteorder != "big": endPtsOfContours.byteswap()