[Zodb-checkins] CVS: Zope3/src/zodb/btrees - BTreeTemplate.c:1.5 BucketTemplate.c:1.7

Tim Peters tim.one@comcast.net
Fri, 21 Feb 2003 17:17:34 -0500


Update of /cvs-repository/Zope3/src/zodb/btrees
In directory cvs.zope.org:/tmp/cvs-serv21763/src/zodb/btrees

Modified Files:
	BTreeTemplate.c BucketTemplate.c 
Log Message:
Cleanup:  In functions with optional arguments that default to None, set
the local var to Py_None instead of to NULL before cracking the arguments.
This saves repeated runtime tests (against both NULL and Py_None) later.
Also renamed local argument vrbls to match the names of the arguments
they represent (in particular, f for min and l for max always confused me,
partly because I have a hard time seeing the difference between "l" and "1",
but mostly because "low" and "high" are also used in these routines, and
"l" reminds too much of low).


=== Zope3/src/zodb/btrees/BTreeTemplate.c 1.4 => 1.5 ===
--- Zope3/src/zodb/btrees/BTreeTemplate.c:1.4	Fri Feb 21 16:47:15 2003
+++ Zope3/src/zodb/btrees/BTreeTemplate.c	Fri Feb 21 17:17:33 2003
@@ -1376,17 +1376,19 @@
 static PyObject *
 BTree_rangeSearch(BTree *self, PyObject *args, PyObject *kw, char type)
 {
-  PyObject *f=0, *l=0;
+  PyObject *min = Py_None;
+  PyObject *max = Py_None;
   int rc;
   Bucket *lowbucket = NULL;
   Bucket *highbucket = NULL;
   int lowoffset;
   int highoffset;
+  PyObject *result;
 
   if (args) {
       if (! PyArg_ParseTupleAndKeywords(args, kw, "|OO",
 					search_keywords,
-					&f, &l))
+					&min, &max))
  	  return NULL;
   }
 
@@ -1397,10 +1399,10 @@
   UNLESS (self->data && self->len) goto empty;
 
   /* Find the low range */
-
-  if (f && f != Py_None)
+  if (min != Py_None)
     {
-      if ((rc = BTree_findRangeEnd(self, f, 1, &lowbucket, &lowoffset)) <= 0)
+      if ((rc = BTree_findRangeEnd(self, min, 1,
+      				   &lowbucket, &lowoffset)) <= 0)
         {
           if (rc < 0) goto err;
           goto empty;
@@ -1414,10 +1416,10 @@
     }
 
   /* Find the high range */
-
-  if (l && l != Py_None)
+  if (max != Py_None)
     {
-      if ((rc = BTree_findRangeEnd(self, l, 0, &highbucket, &highoffset)) <= 0)
+      if ((rc = BTree_findRangeEnd(self, max, 0,
+      				   &highbucket, &highoffset)) <= 0)
         {
           Py_DECREF(lowbucket);
           if (rc < 0) goto err;
@@ -1439,8 +1441,8 @@
       PyPersist_SetATime(highbucket);
     }
 
-  /* It's still possible that the range is empty, even if f < l.  For
-   * example, if f=3 and l=4, and 3 and 4 aren't in the BTree, but 2 and
+  /* It's still possible that the range is empty, even if min < max.  For
+   * example, if min=3 and max=4, and 3 and 4 aren't in the BTree, but 2 and
    * 5 are, then the low position points to the 5 now and the high position
    * points to the 2 now.  They're not necessarily even in the same bucket,
    * so there's no trick we can play with pointer compares to get out
@@ -1452,9 +1454,8 @@
   /* The buckets differ, or they're the same and the offsets show a non-
    * empty range.
    */
-  if (f && f != Py_None             /* both args user-supplied */
-      && l && l != Py_None
-      && lowbucket != highbucket)   /* and different buckets */
+  if (min != Py_None && max != Py_None && /* both args user-supplied */
+      lowbucket != highbucket)   /* and different buckets */
     {
       KEY_TYPE first;
       KEY_TYPE last;
@@ -1478,10 +1479,10 @@
   PyPersist_DECREF(self);
   PyPersist_SetATime(self);
 
-  f = newBTreeItems(type, lowbucket, lowoffset, highbucket, highoffset);
+  result = newBTreeItems(type, lowbucket, lowoffset, highbucket, highoffset);
   Py_DECREF(lowbucket);
   Py_DECREF(highbucket);
-  return f;
+  return result;
 
  err_and_decref_buckets:
   Py_DECREF(lowbucket);


=== Zope3/src/zodb/btrees/BucketTemplate.c 1.6 => 1.7 ===
--- Zope3/src/zodb/btrees/BucketTemplate.c:1.6	Fri Feb 21 16:47:15 2003
+++ Zope3/src/zodb/btrees/BucketTemplate.c	Fri Feb 21 17:17:33 2003
@@ -724,21 +724,22 @@
 Bucket_rangeSearch(Bucket *self, PyObject *args, PyObject *kw,
 		   int *low, int *high)
 {
-  PyObject *f=0, *l=0;
+  PyObject *min = Py_None;
+  PyObject *max = Py_None;
   int rc;
 
   if (args) {
       if (! PyArg_ParseTupleAndKeywords(args, kw, "|OO", search_keywords,
-      					&f,  &l))
+      					&min,  &max))
       return -1;
   }
 
   UNLESS (self->len) goto empty;
 
   /* Find the low range */
-  if (f && f != Py_None)
+  if (min != Py_None)
     {
-      UNLESS (rc = Bucket_findRangeEnd(self, f, 1, 0, low))
+      UNLESS (rc = Bucket_findRangeEnd(self, min, 1, 0, low))
         {
           if (rc < 0) return -1;
           goto empty;
@@ -747,9 +748,9 @@
   else *low = 0;
 
   /* Find the high range */
-  if (l && l != Py_None)
+  if (max != Py_None)
     {
-      UNLESS (rc = Bucket_findRangeEnd(self, l, 0, 0, high))
+      UNLESS (rc = Bucket_findRangeEnd(self, max, 0, 0, high))
         {
           if (rc < 0) return -1;
           goto empty;
@@ -757,7 +758,7 @@
     }
   else *high = self->len - 1;
 
-  /* If f < l to begin with, it's quite possible that low > high now. */
+  /* If min < max to begin with, it's quite possible that low > high now. */
   if (*low <= *high)
     return 0;