[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeTemplate.c:1.6

Tim Peters tim.one@comcast.net
Tue, 11 Jun 2002 14:52:49 -0400


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

Modified Files:
	BTreeTemplate.c 
Log Message:
_BTree_set():  In three places, the length of a child node was accessed
directly without doing the unghostification dance.  Repaired to cache
the child length once in a local vrbl, bracketed by the right
persistence stuff.


=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.5 => 1.6 ===
 {
     int min, grew, copied=1, changed=0, bchanged=0;
+    int childlength;
     BTreeItem *d;
     KEY_TYPE key;
 
@@ -386,14 +387,21 @@
 
     /* A bucket changed size. */
     bchanged = 1;
+
+    UNLESS(PER_USE(d->child))
+        goto err;
+    childlength = d->child->len;
+    PER_ALLOW_DEACTIVATION(d->child);
+    PER_ACCESSED(d->child);
+
     if (value) {
         /* A bucket got bigger. */
         int toobig;
 
         if (SameType_Check(self, d->child))
-            toobig = BTREE(d->child)->len > MAX_BTREE_SIZE(d->child);
+            toobig = childlength > MAX_BTREE_SIZE(d->child);
         else
-            toobig = BUCKET(d->child)->len > MAX_BUCKET_SIZE(d->child);
+            toobig = childlength > MAX_BUCKET_SIZE(d->child);
 
         if (toobig) {
             if (BTree_grow(self, min, noval) < 0)
@@ -411,7 +419,7 @@
             goto err;
         grew = 1; /* Reset flag, since we handled it */
     }
-    if (d->child->len > 0)
+    if (childlength > 0)
         goto Done;
 
     /* The child became empty. */