summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-08-17 15:24:52 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2020-08-18 08:09:42 +0200
commitb7a4c0793ceab4fcde64098e164c36f8fbd48b64 (patch)
treed75585c2db0a37f7884bf049b3c6af023237222a
parent7092efabb5a0488b694418c823463048ddbb310c (diff)
downloadmeson-b7a4c0793ceab4fcde64098e164c36f8fbd48b64.tar.gz
arglist: optimize flush_pre_post
pre_flush_set and post_flush_set are almost always empty, so we can use extend() instead of a for...in loop to add the previous elements of self._container. We can also skip the conversion from deque to list since pre_flush is always appended on the right side. On a QEMU build the time spent in flush_pre_post goes from 1.4 to 0.5 seconds.
-rw-r--r--mesonbuild/arglist.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/mesonbuild/arglist.py b/mesonbuild/arglist.py
index fd4de96f1..4ab7d0990 100644
--- a/mesonbuild/arglist.py
+++ b/mesonbuild/arglist.py
@@ -119,7 +119,7 @@ class CompilerArgs(collections.abc.MutableSequence):
# This correctly deduplicates the entries after _can_dedup definition
# Note: This function is designed to work without delete operations, as deletions are worsening the performance a lot.
def flush_pre_post(self) -> None:
- pre_flush = collections.deque() # type: T.Deque[str]
+ new = list() # type: T.List[str]
pre_flush_set = set() # type: T.Set[str]
post_flush = collections.deque() # type: T.Deque[str]
post_flush_set = set() # type: T.Set[str]
@@ -128,7 +128,7 @@ class CompilerArgs(collections.abc.MutableSequence):
for a in self.pre:
dedup = self._can_dedup(a)
if a not in pre_flush_set:
- pre_flush.append(a)
+ new.append(a)
if dedup is Dedup.OVERRIDEN:
pre_flush_set.add(a)
for a in reversed(self.post):
@@ -140,12 +140,15 @@ class CompilerArgs(collections.abc.MutableSequence):
#pre and post will overwrite every element that is in the container
#only copy over args that are in _container but not in the post flush or pre flush set
+ if pre_flush_set or post_flush_set:
+ for a in self._container:
+ if a not in post_flush_set and a not in pre_flush_set:
+ new.append(a)
+ else:
+ new.extend(self._container)
+ new.extend(post_flush)
- for a in self._container:
- if a not in post_flush_set and a not in pre_flush_set:
- pre_flush.append(a)
-
- self._container = list(pre_flush) + list(post_flush)
+ self._container = new
self.pre.clear()
self.post.clear()