summaryrefslogtreecommitdiff
path: root/mesonbuild/arglist.py
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-11-07 12:12:10 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2025-03-01 16:40:58 +0200
commit25abe40343d549d0fa5e6e50a09ce05647e3145a (patch)
tree5bc5f75fc24067f76931f523fcda7c8b671939dc /mesonbuild/arglist.py
parent92c517ea69e0578515d15061e7ec32f518733acf (diff)
downloadmeson-25abe40343d549d0fa5e6e50a09ce05647e3145a.tar.gz
arglist: optimize __init__()
"Inline" CompilerArgs.__iter__() into CompilerArgs.__init__(), so that replace list(Iterable) is replaced by the much faster list(List). Before: ncalls tottime cumtime 19268 0.163 3.586 arglist.py:97(__init__) After: ncalls tottime cumtime 18674 0.211 3.442 arglist.py:97(__init__) Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/arglist.py')
-rw-r--r--mesonbuild/arglist.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/mesonbuild/arglist.py b/mesonbuild/arglist.py
index 34456581f..2e2542ef9 100644
--- a/mesonbuild/arglist.py
+++ b/mesonbuild/arglist.py
@@ -97,6 +97,12 @@ class CompilerArgs(T.MutableSequence[str]):
def __init__(self, compiler: T.Union['Compiler', 'StaticLinker'],
iterable: T.Optional[T.Iterable[str]] = None):
self.compiler = compiler
+
+ if isinstance(iterable, CompilerArgs):
+ iterable.flush_pre_post()
+ # list(iter(x)) is over two times slower than list(x), so
+ # pass the underlying list to list() directly, instead of an iterator
+ iterable = iterable._container
self._container: T.List[str] = list(iterable) if iterable is not None else []
self.pre: T.Deque[str] = collections.deque()
self.post: T.Deque[str] = collections.deque()
@@ -140,6 +146,7 @@ class CompilerArgs(T.MutableSequence[str]):
self.post.clear()
def __iter__(self) -> T.Iterator[str]:
+ # see also __init__, where this method is essentially inlined
self.flush_pre_post()
return iter(self._container)