Make per-tag sets of selectors more precise and small

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin 2023-01-20 22:52:09 +00:00 committed by Viktor Govako
parent 471abbd754
commit a6daa7121b
3 changed files with 13 additions and 10 deletions

View file

@ -231,10 +231,11 @@ def komap_mapswithme(options):
# Build optimization tree - class/type -> StyleChoosers
for cl in class_order:
clname = cl if cl.find('-') == -1 else cl[:cl.find('-')]
cltags = classificator[cl]
style.build_choosers_tree(clname, "line", cltags)
style.build_choosers_tree(clname, "area", cltags)
style.build_choosers_tree(clname, "node", cltags)
# Get first tag of the class/type.
cltag = next(iter(classificator[cl].keys()))
style.build_choosers_tree(clname, "line", cltag)
style.build_choosers_tree(clname, "area", cltag)
style.build_choosers_tree(clname, "node", cltag)
style.restore_choosers_order("line")
style.restore_choosers_order("area")
style.restore_choosers_order("node")

View file

@ -59,10 +59,12 @@ class Rule():
def extract_tags(self):
a = set()
for condition in self.conditions:
a.add(condition.extract_tag())
if "*" in a:
a = set(["*"])
break
tag = condition.extract_tag()
if tag != '*':
a.add(tag)
elif len(a) == 0:
return set(["*"])
return a

View file

@ -112,7 +112,7 @@ class MapCSS():
else:
logging.error("unparsed zoom: %s" % s)
def build_choosers_tree(self, clname, type, tags={}):
def build_choosers_tree(self, clname, type, cltag):
if type not in self.choosers_by_type_and_tag:
self.choosers_by_type_and_tag[type] = {}
if clname not in self.choosers_by_type_and_tag[type]:
@ -120,7 +120,7 @@ class MapCSS():
if type in self.choosers_by_type:
for chooser in self.choosers_by_type[type]:
for tag in chooser.extract_tags():
if tag == "*" or tag in tags:
if tag == "*" or tag == cltag:
if chooser not in self.choosers_by_type_and_tag[type][clname]:
self.choosers_by_type_and_tag[type][clname].add(chooser)
break