Rev 2505: Avoiding the string format unless there is actually a problem in http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex

John Arbash Meinel john at arbash-meinel.com
Fri May 4 22:49:04 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.17-dev/dirstate_pyrex

------------------------------------------------------------
revno: 2505
revision-id: john at arbash-meinel.com-20070504214853-iqaht2z8963hdlr3
parent: john at arbash-meinel.com-20070504214147-ckrxzu7bepvcs4ct
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate_pyrex
timestamp: Fri 2007-05-04 16:48:53 -0500
message:
  Avoiding the string format unless there is actually a problem
  saves us almost 50ms (down to 242ms)
modified:
  bzrlib/compiled/dirstate_helpers.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
-------------- next part --------------
=== modified file 'bzrlib/compiled/dirstate_helpers.pyx'
--- a/bzrlib/compiled/dirstate_helpers.pyx	2007-05-04 21:41:47 +0000
+++ b/bzrlib/compiled/dirstate_helpers.pyx	2007-05-04 21:48:53 +0000
@@ -249,16 +249,18 @@
 
 
 cdef void _parse_dirblocks_0_parents(object state, object fields,
-                                     int entry_size, int pos,
-                                     int field_count):
+                                     int entry_size, int pos):
     cdef object current_block
     cdef object entry
     cdef void * current_dirname
     cdef int new_block
+    cdef int field_count
 
     if not PyList_CheckExact(fields):
         raise TypeError('fields must be a list')
 
+    field_count = len(fields)
+
     state._dirblocks = [('', []), ('', [])]
     current_block = state._dirblocks[0][1]
     obj = ''
@@ -334,6 +336,8 @@
     cdef int entry_size
     cdef int field_count
     cdef int num_present_parents
+    cdef int expected_field_count
+    cdef int num_entries
     cdef char *next_field
 
     state._state_file.seek(state._end_of_header)
@@ -342,6 +346,9 @@
 
     reader = Reader(text)
 
+    num_present_parents = state._num_present_parents()
+    entry_size = state._fields_per_entry()
+
     fields = reader.get_all_fields()
 
     # skip the first field which is the trailing null from the header.
@@ -353,23 +360,24 @@
     #  3 fields for the key
     #  + number of fields per tree_data (5) * tree count
     #  + newline
-    num_present_parents = state._num_present_parents()
-    tree_count = 1 + num_present_parents
-    entry_size = state._fields_per_entry()
-    expected_field_count = entry_size * state._num_entries
+    num_entries = state._num_entries
+    expected_field_count = entry_size * num_entries
     field_count = len(fields)
-    # this checks our adjustment, and also catches file too short.
-    assert field_count - cur == expected_field_count, \
-        'field count incorrect %s != %s, entry_size=%s, '\
-        'num_entries=%s fields=%r' % (
-            field_count - cur, expected_field_count, entry_size,
-            state._num_entries, fields)
+    if field_count - cur != expected_field_count:
+        # this checks our adjustment, and also catches file too short.
+        raise AssertionError(
+            'field count incorrect %s != %s, entry_size=%s, '
+            'num_entries=%s fields=%r' % (
+                field_count - cur, expected_field_count, entry_size,
+                state._num_entries, fields))
 
     if num_present_parents == 0:
         # Move the iterator to the current position
-        _parse_dirblocks_0_parents(state, fields, entry_size, cur,
-                                   field_count)
-    elif num_present_parents == 1:
+        #fields = reader.get_all_fields()
+        _parse_dirblocks_0_parents(state, fields, entry_size, 1)
+        state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
+        return
+    if num_present_parents == 1:
         # Bind external functions to local names
         _int = int
         # We access all fields in order, so we can just iterate over



More information about the bazaar-commits mailing list