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

Jeremy Hylton jeremy@zope.com
Wed, 27 Feb 2002 00:40:19 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	BTreeItemsTemplate.c 
Log Message:
Reformat BTreeItems_length_or_nonzero().

(In search of refcount bugs, none found yet.)



=== Zope3/lib/python/Persistence/BTrees/BTreeItemsTemplate.c 1.1.2.1 => 1.1.2.2 ===
 BTreeItems_length_or_nonzero(BTreeItems *self, int nonzero)
 {
-  int r;
-  Bucket *b, *next;
+    int r;
+    Bucket *b, *next;
 
-  b=self->firstbucket;
-  UNLESS(b) return 0;
-
-  r=self->last + 1 - self->first;
-
-  if (nonzero && r > 0) 
-    /* Short-circuit if all we care about is nonempty */
-    return 1;
-
-  if (b == self->lastbucket) return r;
-
-  Py_INCREF(b);
-  PER_USE_OR_RETURN(b, -1);
-  while ((next=b->next)) 
-    {
-      r += b->len;
-      if (nonzero && r > 0) 
-        /* Short-circuit if all we care about is nonempty */
-        break;
-
-      if (next == self->lastbucket) 
-        break; /* we already counted the last bucket */
-
-      Py_INCREF(next);
-      PER_ALLOW_DEACTIVATION(b);
-      PER_ACCESSED(b);
-      Py_DECREF(b);
-      b=next;
-      PER_USE_OR_RETURN(b, -1);
+    b = self->firstbucket;
+    if (b == NULL)
+	return 0;
+
+    r = self->last + 1 - self->first;
+
+    if (nonzero && r > 0) 
+	/* Short-circuit if all we care about is nonempty */
+	return 1;
+
+    if (b == self->lastbucket) 
+	return r;
+
+    Py_INCREF(b);
+    PER_USE_OR_RETURN(b, -1);
+    while ((next = b->next)) {
+	r += b->len;
+	if (nonzero && r > 0) 
+	    /* Short-circuit if all we care about is nonempty */
+	    break;
+
+	if (next == self->lastbucket) 
+	    break; /* we already counted the last bucket */
+
+	Py_INCREF(next);
+	PER_ALLOW_DEACTIVATION(b);
+	PER_ACCESSED(b);
+	Py_DECREF(b);
+	b = next;
+	PER_USE_OR_RETURN(b, -1);
     }
-  PER_ALLOW_DEACTIVATION(b);
-  PER_ACCESSED(b);
-  Py_DECREF(b);
+    PER_ALLOW_DEACTIVATION(b);
+    PER_ACCESSED(b);
+    Py_DECREF(b);
 
-  return r >= 0 ? r : 0;
+    return r >= 0 ? r : 0;
 }
 
 static int