[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeItemsTemplate.c:1.5

Tim Peters tim.one@comcast.net
Mon, 17 Jun 2002 22:41:57 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv31147

Modified Files:
	BTreeItemsTemplate.c 
Log Message:
BTreeItems_seek():  Simplify the use of persistence macros.  This routine
is now almost as simple as it's been trying to be <wink>.


=== Zope3/lib/python/Persistence/BTrees/BTreeItemsTemplate.c 1.4 => 1.5 ===
     }
 
-    PER_USE_OR_RETURN(currentbucket, -1);
     delta = i - pseudoindex;
     while (delta > 0) {         /* move right */
         int max;
         /* Want to move right delta positions; the most we can move right in
          * this bucket is currentbucket->len - currentoffset - 1 positions.
          */
+        PER_USE_OR_RETURN(currentbucket, -1);
         max = currentbucket->len - currentoffset - 1;
+        b = currentbucket->next;
+        PER_ALLOW_DEACTIVATION(currentbucket);
+        PER_ACCESSED(currentbucket);
         if (delta <= max) {
             currentoffset += delta;
             pseudoindex += delta;
             if (currentbucket == self->lastbucket
-                && currentoffset > self->last) {
-                PER_ALLOW_DEACTIVATION(currentbucket);
-                PER_ACCESSED(currentbucket);
-                goto no_match;
-            }
+                && currentoffset > self->last) goto no_match;
             break;
         }
         /* Move to start of next bucket. */
-        b = currentbucket->next;
-        PER_ALLOW_DEACTIVATION(currentbucket);
-        PER_ACCESSED(currentbucket);
         if (currentbucket == self->lastbucket || b == NULL) goto no_match;
         currentbucket = b;
-        PER_USE_OR_RETURN(currentbucket, -1);
         pseudoindex += max + 1;
         delta -= max + 1;
         currentoffset = 0;
@@ -197,29 +192,23 @@
             currentoffset += delta;
             pseudoindex += delta;
             if (currentbucket == self->firstbucket
-                && currentoffset < self->first) {
-                PER_ALLOW_DEACTIVATION(currentbucket);
-                PER_ACCESSED(currentbucket);
-                goto no_match;
-            }
+                && currentoffset < self->first) goto no_match;
             break;
         }
         /* Move to end of previous bucket. */
-        PER_ALLOW_DEACTIVATION(currentbucket);
-        PER_ACCESSED(currentbucket);
         if (currentbucket == self->firstbucket) goto no_match;
         status = PreviousBucket(&currentbucket, self->firstbucket);
         if (status == 0)
             goto no_match;
         else if (status < 0)
             return -1;
-        PER_USE_OR_RETURN(currentbucket, -1);
         pseudoindex -= currentoffset + 1;
         delta += currentoffset + 1;
+        PER_USE_OR_RETURN(currentbucket, -1);
         currentoffset = currentbucket->len - 1;
+        PER_ALLOW_DEACTIVATION(currentbucket);
+        PER_ACCESSED(currentbucket);
     }
-    PER_ALLOW_DEACTIVATION(currentbucket);
-    PER_ACCESSED(currentbucket);
 
     assert(pseudoindex == i);
     Py_INCREF(currentbucket);