mirror of
https://github.com/servo/servo.git
synced 2025-06-08 16:43:28 +00:00
Use itertools.groupby in generatePrefableArray
This commit is contained in:
parent
b094932d57
commit
bee6f59b16
1 changed files with 8 additions and 26 deletions
|
@ -5,6 +5,7 @@
|
||||||
# Common codegen classes.
|
# Common codegen classes.
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
import re
|
import re
|
||||||
|
@ -1406,37 +1407,18 @@ class PropertyDefiner:
|
||||||
# members while still allowing us to define all the members in the smallest
|
# members while still allowing us to define all the members in the smallest
|
||||||
# number of JSAPI calls.
|
# number of JSAPI calls.
|
||||||
assert len(array) != 0
|
assert len(array) != 0
|
||||||
# So we won't put a specTerminator at the very front of the list:
|
|
||||||
lastCondition = getCondition(array[0], self.descriptor)
|
|
||||||
specs = []
|
specs = []
|
||||||
currentSpecs = []
|
|
||||||
prefableSpecs = []
|
prefableSpecs = []
|
||||||
|
|
||||||
prefableTemplate = ' Prefable { pref: %s, specs: %s[%d], terminator: %s }'
|
prefableTemplate = ' Prefable { pref: %s, specs: %s[%d], terminator: %s }'
|
||||||
|
hasTerminator = 'true' if specTerminator else 'false'
|
||||||
|
|
||||||
def switchToCondition(props, condition):
|
for cond, members in groupby(array, lambda m: getCondition(m, self.descriptor)):
|
||||||
prefableSpecs.append(prefableTemplate %
|
currentSpecs = [specTemplate % getDataTuple(m) for m in members]
|
||||||
(condition,
|
if specTerminator:
|
||||||
name + "_specs",
|
currentSpecs.append(specTerminator)
|
||||||
len(specs),
|
|
||||||
'true' if specTerminator else 'false'))
|
|
||||||
specs.append("&[\n" + ",\n".join(currentSpecs) + "]\n")
|
specs.append("&[\n" + ",\n".join(currentSpecs) + "]\n")
|
||||||
del currentSpecs[:]
|
prefableSpecs.append(
|
||||||
|
prefableTemplate % (cond, name + "_specs", len(specs) - 1, hasTerminator))
|
||||||
for member in array:
|
|
||||||
curCondition = getCondition(member, self.descriptor)
|
|
||||||
if lastCondition != curCondition:
|
|
||||||
# Terminate previous list
|
|
||||||
if specTerminator:
|
|
||||||
currentSpecs.append(specTerminator)
|
|
||||||
# And switch to our new pref
|
|
||||||
switchToCondition(self, lastCondition)
|
|
||||||
lastCondition = curCondition
|
|
||||||
# And the actual spec
|
|
||||||
currentSpecs.append(specTemplate % getDataTuple(member))
|
|
||||||
if specTerminator:
|
|
||||||
currentSpecs.append(specTerminator)
|
|
||||||
switchToCondition(self, lastCondition)
|
|
||||||
|
|
||||||
specsArray = ("const %s_specs: &'static [&'static[%s]] = &[\n" +
|
specsArray = ("const %s_specs: &'static [&'static[%s]] = &[\n" +
|
||||||
",\n".join(specs) + "\n" +
|
",\n".join(specs) + "\n" +
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue