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.
pull/5227/merge
Dylan Baker 6 years ago
parent 914b591692
commit 506f8708ba
  1. 12
      mesonbuild/mesonlib.py

@ -537,22 +537,22 @@ class Version:
return (a > b) - (a < b) return (a > b) - (a < b)
# compare each sequence in order # 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 # sort a non-digit sequence before a digit sequence
if self._v[i].isdigit() != other._v[i].isdigit(): if ours.isdigit() != theirs.isdigit():
return 1 if self._v[i].isdigit() else -1 return 1 if ours.isdigit() else -1
# compare as numbers # compare as numbers
if self._v[i].isdigit(): if ours.isdigit():
# because leading zeros have already been removed, if one number # because leading zeros have already been removed, if one number
# has more digits, it is greater # 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: if c != 0:
return c return c
# fallthrough # fallthrough
# compare lexicographically # compare lexicographically
c = cmp(self._v[i], other._v[i]) c = cmp(ours, theirs)
if c != 0: if c != 0:
return c return c

Loading…
Cancel
Save