Rev 2492: Add an integer-size comparison loop at the begining, and in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex
John Arbash Meinel
john at arbash-meinel.com
Fri May 4 17:35:35 BST 2007
At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex
------------------------------------------------------------
revno: 2492
revision-id: john at arbash-meinel.com-20070504163523-69dypgt24ipo26p2
parent: john at arbash-meinel.com-20070504161941-7n3we92jhxnczl5a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate_pyrex
timestamp: Fri 2007-05-04 11:35:23 -0500
message:
Add an integer-size comparison loop at the begining, and
update the test suite to make sure we are properly exercising it.
modified:
bzrlib/compiled/dirstate_helpers.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
bzrlib/tests/compiled/test_dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
-------------- next part --------------
=== modified file 'bzrlib/compiled/dirstate_helpers.pyx'
--- a/bzrlib/compiled/dirstate_helpers.pyx 2007-05-04 16:19:41 +0000
+++ b/bzrlib/compiled/dirstate_helpers.pyx 2007-05-04 16:35:23 +0000
@@ -145,12 +145,30 @@
cdef char *cur2
cdef char *end1
cdef char *end2
+ cdef int *cur_int1
+ cdef int *cur_int2
+ cdef int *end_int1
+ cdef int *end_int2
- cur1 = path1
- cur2 = path2
+ cur_int1 = <int*>path1
+ cur_int2 = <int*>path2
+ end_int1 = <int*>(path1 + size1 - (size1%4))
+ end_int2 = <int*>(path2 + size2 - (size2%4))
end1 = path1+size1
end2 = path2+size2
+ # Use 32-bit comparisons for the matching portion of the string.
+ # Almost all CPU's are faster at loading and comparing 32-bit integers,
+ # than they are at 8-bit integers.
+ while cur_int1 < end_int1 and cur_int2 < end_int2:
+ if cur_int1[0] != cur_int2[0]:
+ break
+ cur_int1 = cur_int1 + 1
+ cur_int2 = cur_int2 + 1
+
+ cur1 = <char*>cur_int1
+ cur2 = <char*>cur_int2
+
while cur1 < end1 and cur2 < end2:
if cur1[0] == cur2[0]:
# This character matches, just go to the next one
@@ -176,7 +194,7 @@
if cur1 < end1:
# Must have reached path2 first, so it comes first
return 1
- if cur2 < end1:
+ if cur2 < end2:
# Must have reached path1 first, it comes first
return -1
# We reached the end of both strings
@@ -185,7 +203,7 @@
def cmp_dirblock_strings(path1, path2):
"""Compare to python strings in dirblock fashion."""
- return _cmp_dirblock_strings(PyString_AsString(path1),
+ return _cmp_dirblock_strings_alt(PyString_AsString(path1),
PyString_Size(path1),
PyString_AsString(path2),
PyString_Size(path2))
=== modified file 'bzrlib/tests/compiled/test_dirstate_helpers.py'
--- a/bzrlib/tests/compiled/test_dirstate_helpers.py 2007-05-04 03:58:29 +0000
+++ b/bzrlib/tests/compiled/test_dirstate_helpers.py 2007-05-04 16:35:23 +0000
@@ -76,26 +76,57 @@
"""Compare against the empty string."""
self.assertStrCmp(0, '', '')
self.assertStrCmp(1, 'a', '')
- self.assertStrCmp(1, 'b', '')
- self.assertStrCmp(1, 'testing', '')
+ self.assertStrCmp(1, 'ab', '')
+ self.assertStrCmp(1, 'abc', '')
+ self.assertStrCmp(1, 'abcd', '')
+ self.assertStrCmp(1, 'abcde', '')
+ self.assertStrCmp(1, 'abcdef', '')
+ self.assertStrCmp(1, 'abcdefg', '')
+ self.assertStrCmp(1, 'abcdefgh', '')
+ self.assertStrCmp(1, 'abcdefghi', '')
self.assertStrCmp(1, 'test/ing/a/path/', '')
def test_cmp_same_str(self):
"""Compare the same string"""
self.assertStrCmp(0, 'a', 'a')
- self.assertStrCmp(0, 'b', 'b')
+ self.assertStrCmp(0, 'ab', 'ab')
+ self.assertStrCmp(0, 'abc', 'abc')
+ self.assertStrCmp(0, 'abcd', 'abcd')
+ self.assertStrCmp(0, 'abcde', 'abcde')
+ self.assertStrCmp(0, 'abcdef', 'abcdef')
+ self.assertStrCmp(0, 'abcdefg', 'abcdefg')
+ self.assertStrCmp(0, 'abcdefgh', 'abcdefgh')
+ self.assertStrCmp(0, 'abcdefghi', 'abcdefghi')
self.assertStrCmp(0, 'testing a long string', 'testing a long string')
self.assertStrCmp(0, 'x'*10000, 'x'*10000)
- self.assertStrCmp(0, 'x y', 'x' + ' ' + 'y')
+ self.assertStrCmp(0, 'a/b', 'a/b')
+ self.assertStrCmp(0, 'a/b/c', 'a/b/c')
self.assertStrCmp(0, 'a/b/c/d', 'a/b/c/d')
+ self.assertStrCmp(0, 'a/b/c/d/e', 'a/b/c/d/e')
def test_simple_paths(self):
"""Compare strings that act like normal string comparison"""
self.assertStrCmp(-1, 'a', 'b')
- self.assertStrCmp(-1, 'b', 'c')
- self.assertStrCmp(1, 'd', 'c')
- self.assertStrCmp(-1, 'testing a long string', 'testing b long string')
- self.assertStrCmp(-1, 'a/b/c/d', 'a/c/c/d')
+ self.assertStrCmp(-1, 'aa', 'ab')
+ self.assertStrCmp(-1, 'ab', 'bb')
+ self.assertStrCmp(-1, 'aaa', 'aab')
+ self.assertStrCmp(-1, 'aab', 'abb')
+ self.assertStrCmp(-1, 'abb', 'bbb')
+ self.assertStrCmp(-1, 'aaaa', 'aaab')
+ self.assertStrCmp(-1, 'aaab', 'aabb')
+ self.assertStrCmp(-1, 'aabb', 'abbb')
+ self.assertStrCmp(-1, 'abbb', 'bbbb')
+ self.assertStrCmp(-1, 'aaaaa', 'aaaab')
+ self.assertStrCmp(-1, 'a/a', 'a/b')
+ self.assertStrCmp(-1, 'a/b', 'b/b')
+ self.assertStrCmp(-1, 'a/a/a', 'a/a/b')
+ self.assertStrCmp(-1, 'a/a/b', 'a/b/b')
+ self.assertStrCmp(-1, 'a/b/b', 'b/b/b')
+ self.assertStrCmp(-1, 'a/a/a/a', 'a/a/a/b')
+ self.assertStrCmp(-1, 'a/a/a/b', 'a/a/b/b')
+ self.assertStrCmp(-1, 'a/a/b/b', 'a/b/b/b')
+ self.assertStrCmp(-1, 'a/b/b/b', 'b/b/b/b')
+ self.assertStrCmp(-1, 'a/a/a/a/a', 'a/a/a/a/b')
def test_tricky_paths(self):
self.assertStrCmp(1, 'ab/cd/ef', 'ab/cc/ef')
More information about the bazaar-commits
mailing list