aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2019-04-22 16:02:40 -0700
committerDylan Baker <dylan@pnwbakers.com>2019-04-25 12:28:51 -0700
commit506f8708ba71be572b885e4b59cc4abd4156be0d (patch)
tree9f01158507ace74145fadb9d9357ddc3b6e3274e /mesonbuild/mesonlib.py
parent914b591692c66cd9516da70930f4c6768ea93302 (diff)
downloadmeson-506f8708ba71be572b885e4b59cc4abd4156be0d.zip
meson-506f8708ba71be572b885e4b59cc4abd4156be0d.tar.gz
meson-506f8708ba71be572b885e4b59cc4abd4156be0d.tar.bz2
mesonlib: use zip() in Version
Instead of range. This makes version comparison 25-50% faster depending on the operator and how different the values are.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r--mesonbuild/mesonlib.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 25e15e4..a9d4391 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -537,22 +537,22 @@ class Version:
return (a > b) - (a < b)
# compare each sequence in order
- for i in range(0, min(len(self._v), len(other._v))):
+ for ours, theirs in zip(self._v, other._v):
# sort a non-digit sequence before a digit sequence
- if self._v[i].isdigit() != other._v[i].isdigit():
- return 1 if self._v[i].isdigit() else -1
+ if ours.isdigit() != theirs.isdigit():
+ return 1 if ours.isdigit() else -1
# compare as numbers
- if self._v[i].isdigit():
+ if ours.isdigit():
# because leading zeros have already been removed, if one number
# has more digits, it is greater
- c = cmp(len(self._v[i]), len(other._v[i]))
+ c = cmp(len(ours), len(theirs))
if c != 0:
return c
# fallthrough
# compare lexicographically
- c = cmp(self._v[i], other._v[i])
+ c = cmp(ours, theirs)
if c != 0:
return c