aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-08-17 15:39:50 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2020-08-18 08:11:25 +0200
commit372f420778f8f4b55b207f9a6be2c20e2bd22c38 (patch)
tree51994fdd8fd79c4efc0dddc982750b1fcdf4a011
parent3d4fb02e2907b2532333fdb5eefe6335c7cd94c4 (diff)
downloadmeson-372f420778f8f4b55b207f9a6be2c20e2bd22c38.zip
meson-372f420778f8f4b55b207f9a6be2c20e2bd22c38.tar.gz
meson-372f420778f8f4b55b207f9a6be2c20e2bd22c38.tar.bz2
File: precompute hash
Most files are going to be looked up into a set or dictionary. Precompute the hash so that we only need to do so once and we can also use it to quickly weed out unequal objects. On a QEMU build, the time spent in __eq__ and __hash goes respectively from 3.110s to 2.162s and from 0.648s to 0.299s. Even larger gains are obtained by the next patch.
-rw-r--r--mesonbuild/mesonlib.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 4b8cce8..760b235 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -242,6 +242,7 @@ class File:
self.is_built = is_built
self.subdir = subdir
self.fname = fname
+ self.hash = hash((is_built, subdir, fname))
def __str__(self) -> str:
return self.relative_name()
@@ -291,10 +292,12 @@ class File:
def __eq__(self, other) -> bool:
if not isinstance(other, File):
return NotImplemented
+ if self.hash != other.hash:
+ return False
return (self.fname, self.subdir, self.is_built) == (other.fname, other.subdir, other.is_built)
def __hash__(self) -> int:
- return hash((self.fname, self.subdir, self.is_built))
+ return self.hash
@lru_cache(maxsize=None)
def relative_name(self) -> str: