Author: Stian Andreassen
Branch:
Changeset: r58739:e70778239285
Date: 2012-11-05 15:47 +0100
http://bitbucket.org/pypy/pypy/changeset/e70778239285/
Log: Give rbigint.eq a faster path (atleast it benchmarks slightly
faster)
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -337,6 +337,11 @@
if (self.sign != other.sign or
self.numdigits() != other.numdigits()):
return False
+
+ # Fast path.
+ if len(self._digits) == len(other._digits):
+ return self._digits == other._digits
+
i = 0
ld = self.numdigits()
while i < ld:
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -300,6 +300,13 @@
assert not f1.eq(f2)
assert not f1.eq(f3)
+ def test_eq_fastpath(self):
+ x = 1234
+ y = 1234
+ f1 = rbigint.fromint(x)
+ f2 = rbigint.fromint(y)
+ assert f1.eq(f2)
+
def test_lt(self):
val = [0, 0x111111111111, 0x111111111112, 0x111111111112FFFF]
for x in gen_signs(val):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit