aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVirgil Dupras <vdupras@gentoo.org>2018-09-17 19:31:27 -0400
committerVirgil Dupras <vdupras@gentoo.org>2018-09-17 19:31:27 -0400
commitce821ea62cd40b0110fc128f92e140da4e7482cf (patch)
tree36121fdbb39908e631e7dfdcc47970951024ef77
parentGreatly speed up "equery depends" (diff)
downloadgentoolkit-ce821ea62cd40b0110fc128f92e140da4e7482cf.tar.gz
gentoolkit-ce821ea62cd40b0110fc128f92e140da4e7482cf.tar.bz2
gentoolkit-ce821ea62cd40b0110fc128f92e140da4e7482cf.zip
Atom.intersects: simplify name-only matching logicHEADmaster
Remove old "optimization". Slicing two strings can't possibly be faster than checking if `.category` is `None`: the call to `.cp` earlier ensures that we've already populated that property. Also, add tests for it.
-rw-r--r--pym/gentoolkit/atom.py12
-rw-r--r--pym/gentoolkit/test/test_atom.py11
2 files changed, 12 insertions, 11 deletions
diff --git a/pym/gentoolkit/atom.py b/pym/gentoolkit/atom.py
index b5b755c..b86c89c 100644
--- a/pym/gentoolkit/atom.py
+++ b/pym/gentoolkit/atom.py
@@ -209,15 +209,9 @@ class Atom(portage.dep.Atom, CPV):
# Our "cp" (cat/pkg) must match exactly:
if self.cp != other.cp:
# Check to see if one is name only:
- # Avoid slow partitioning if we're definitely not matching
- # (yes, this is hackish, but it's faster):
- if self.cp[-1:] != other.cp[-1:]:
- return False
-
- if ((not self.category and self.name == other.name) or
- (not other.category and other.name == self.name)):
- return True
- return False
+ # We don't bother checking if self.category is None: it can't be
+ # because we're an Atom subclass and that would be invalid.
+ return (not other.category and self.name == other.name)
# Slot dep only matters if we both have one. If we do they
# must be identical:
diff --git a/pym/gentoolkit/test/test_atom.py b/pym/gentoolkit/test/test_atom.py
index 399905e..6177222 100644
--- a/pym/gentoolkit/test/test_atom.py
+++ b/pym/gentoolkit/test/test_atom.py
@@ -8,6 +8,7 @@
import unittest
from gentoolkit.atom import Atom
+from gentoolkit.cpv import CPV
from gentoolkit.test import cmp
"""Atom test suite (verbatim) from pkgcore."""
@@ -140,10 +141,16 @@ class TestGentoolkitAtom(unittest.TestCase):
result, that_atom.intersects(this_atom),
'%s intersecting %s should be %s' % (that, this, result))
+ def test_intersects_nameonly(self):
+ atom = Atom('cat/pkg')
+ self.assertTrue(atom.intersects(CPV('pkg')))
+ self.assertFalse(atom.intersects(CPV('other')))
+ self.assertFalse(atom.intersects(CPV('dkg')))
+
def test_main():
- suite = unittest.TestLoader().loadTestsFromTestCase(TestGentoolkitAtom)
- unittest.TextTestRunner(verbosity=2).run(suite)
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestGentoolkitAtom)
+ unittest.TextTestRunner(verbosity=2).run(suite)
test_main.__test__ = False