Rev 4674: Switch to using a for loop, and add only when checking last rather than in http://bazaar.launchpad.net/~jameinel/bzr/2.1-btree-simple-parse

John Arbash Meinel john at arbash-meinel.com
Fri Sep 4 22:16:26 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-btree-simple-parse

------------------------------------------------------------
revno: 4674
revision-id: john at arbash-meinel.com-20090904211614-5bvq376yxdix319n
parent: john at arbash-meinel.com-20090904204912-e6mvz39tpx6u2ii2
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-btree-simple-parse
timestamp: Fri 2009-09-04 16:16:14 -0500
message:
  Switch to using a for loop, and add only when checking last rather than
  subtracting on every key.
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx	2009-09-04 20:49:12 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx	2009-09-04 21:16:14 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Canonical Ltd
+# Copyright (C) 2008, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -143,14 +143,12 @@
         cdef char *temp_ptr
         cdef int loop_counter
         # keys are tuples
-        loop_counter = 0
         key = PyTuple_New(self.key_length)
-        while loop_counter < self.key_length:
-            loop_counter = loop_counter + 1
+        for loop_counter from 0 <= loop_counter < self.key_length:
             # grab a key segment
             temp_ptr = <char*>memchr(self._start, c'\0', last - self._start)
             if temp_ptr == NULL:
-                if loop_counter == self.key_length:
+                if loop_counter + 1 == self.key_length:
                     # capture to last
                     temp_ptr = last
                 else:
@@ -168,7 +166,7 @@
             # advance our pointer
             self._start = temp_ptr + 1
             Py_INCREF(key_element)
-            PyTuple_SET_ITEM(key, loop_counter - 1, key_element)
+            PyTuple_SET_ITEM(key, loop_counter, key_element)
         return key
 
     cdef int process_line(self) except -1:



More information about the bazaar-commits mailing list