Check for overflows in a loop

This commit is contained in:
Simon Cozens 2021-09-15 11:08:50 +01:00
parent f9b927cdbb
commit f53a75fb1d

View File

@ -377,12 +377,6 @@ class ChainContextualBuilder(LookupBuilder):
candidates = [None, None, None, []]
for rule in ruleset.rules:
candidates[3].append(self.buildFormat3Subtable(rule, chaining))
# Check we can build it
try:
self.getCompiledSize_(candidates[3])
except Exception as e:
log.warning("Contextual format 3 at %s overflowed" % str(self.location))
candidates[3] = None
# Can we express the whole ruleset as a format 2 subtable?
classdefs = ruleset.format2ClassDefs()
@ -390,21 +384,19 @@ class ChainContextualBuilder(LookupBuilder):
candidates[2] = [
self.buildFormat2Subtable(ruleset, classdefs, chaining)
]
# Check we can build it
try:
self.getCompiledSize_(candidates[2])
except Exception as e:
log.warning("Contextual format 2 at %s overflowed (%s)" % (str(self.location), e))
candidates[2] = None
if not ruleset.hasAnyGlyphClasses:
candidates[1] = [self.buildFormat1Subtable(ruleset, chaining)]
# Check we can build it
for i in [1, 2, 3]:
try:
self.getCompiledSize_(candidates[1])
self.getCompiledSize_(candidates[i])
except Exception as e:
log.warning("Contextual format 1 at %s overflowed" % str(self.location))
candidates[1] = None
log.warning(
"Contextual format %i at %s overflowed (%s)"
% (i, str(self.location), e)
)
candidates[i] = None
candidates = [x for x in candidates if x is not None]
if not candidates: