[Zodb-checkins] CVS: Zope/lib/python/BTrees - BTreeItemsTemplate.c:1.16

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


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv30582

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>.


=== Zope/lib/python/BTrees/BTreeItemsTemplate.c 1.15 => 1.16 ===
     }
 
-    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;
@@ -196,29 +191,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);