Skip to content

Commit 4da7791

Browse files
committed
Reduce include paths further
by 0.45% for Mbed Cloud Client
1 parent 8292aff commit 4da7791

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tools/resources/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def __init__(self, notify, collect_ignores=False):
136136
# Incremental scan related
137137
self._label_paths = []
138138
self._labels = {"TARGET": [], "TOOLCHAIN": [], "FEATURE": []}
139+
self._prefixed_labels = set()
139140

140141
# Path seperator style (defaults to OS-specific seperator)
141142
self._sep = sep
@@ -217,12 +218,12 @@ def __str__(self):
217218

218219
def _add_labels(self, prefix, labels):
219220
self._labels[prefix].extend(labels)
220-
prefixed_labels = set("%s_%s" % (prefix, label) for label in labels)
221+
self._prefixed_labels |= set("%s_%s" % (prefix, label) for label in labels)
221222
for path, base_path, into_path in self._label_paths:
222-
if basename(path) in prefixed_labels:
223+
if basename(path) in self._prefixed_labels:
223224
self.add_directory(path, base_path, into_path)
224225
self._label_paths = [(p, b, i) for p, b, i in self._label_paths
225-
if basename(p) not in prefixed_labels]
226+
if basename(p) not in self._prefixed_labels]
226227

227228
def add_target_labels(self, target):
228229
self._add_labels("TARGET", target.labels)
@@ -276,7 +277,11 @@ def get_file_refs(self, file_type):
276277
def _all_parents(self, files):
277278
for name in files:
278279
components = name.split(self._sep)
279-
start_at = 2 if components[0] == '' else 1
280+
start_at = 2 if components[0] in set(['', '.']) else 1
281+
for index, directory in reversed(list(enumerate(components))[start_at:]):
282+
if directory in self._prefixed_labels:
283+
start_at = index + 1
284+
break
280285
for n in range(start_at, len(components)):
281286
parent = self._sep.join(components[:n])
282287
yield parent

0 commit comments

Comments
 (0)