[Zope-Checkins] CVS: Zope/lib/python/BTrees - BTreeTemplate.c:1.69 BucketTemplate.c:1.46 Maintainer.txt:1.13 _fsBTree.c:1.4 intkeymacros.h:1.10 intvaluemacros.h:1.8 objectkeymacros.h:1.4 objectvaluemacros.h:1.4

Tim Peters tim.one@comcast.net
Wed, 26 Jun 2002 20:32:54 -0400


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

Modified Files:
	BTreeTemplate.c BucketTemplate.c Maintainer.txt _fsBTree.c 
	intkeymacros.h intvaluemacros.h objectkeymacros.h 
	objectvaluemacros.h 
Log Message:
Backported the BTree KEY_TYPE_IS_PYOBJECT and VALUE_TYPE_IS_PYOBJECT
macros from Zope3.  These allow converting some runtime tests into
compile-time specialization, and that's going to be more important for
work on speeding "lopsided merges".


=== Zope/lib/python/BTrees/BTreeTemplate.c 1.68 => 1.69 ===
 
         for (i = 1; i < len; i++) {
+#ifdef KEY_TYPE_IS_PYOBJECT
 	    DECREF_KEY(self->data[i].key);
+#endif
             Py_DECREF(self->data[i].child);
         }
 	free(self->data);


=== Zope/lib/python/BTrees/BucketTemplate.c 1.45 => 1.46 ===
 _bucket_clear(Bucket *self)
 {
-  int i;
+    const int len = self->len;
+    /* Don't declare i at this level.  If neither keys nor values are
+     * PyObject*, i won't be referenced, and you'll get a nuisance compiler
+     * wng for declaring it here.
+     */
+    self->len = self->size = 0;
 
-  if (self->next)
-    {
-      Py_DECREF(self->next);
-      self->next=0;
+    if (self->next) {
+        Py_DECREF(self->next);
+        self->next = NULL;
     }
 
-  for (i=self->len; --i >= 0; )
-    {
-      DECREF_KEY(self->keys[i]);
-      if (self->values)
-        {
-          DECREF_VALUE(self->values[i]);
-        }
-    }
-  self->len=0;
-  if (self->values)
-    {
-      free(self->values);
-      self->values=0;
-    }
-  if (self->keys)
-    {
-      free(self->keys);
-      self->keys=0;
+    /* Silence compiler warning about unused variable len for the case
+       when neither key nor value is an object, i.e. II. */
+    (void)len;
+
+    if (self->keys) {
+#ifdef KEY_TYPE_IS_PYOBJECT
+        int i;
+        for (i = 0; i < len; ++i)
+            DECREF_KEY(self->keys[i]);
+#endif
+        free(self->keys);
+        self->keys = NULL;
     }
-  self->size=0;
 
-  return 0;
+    if (self->values) {
+#ifdef VALUE_TYPE_IS_PYOBJECT
+        int i;
+        for (i = 0; i < len; ++i)
+            DECREF_VALUE(self->values[i]);
+#endif
+        free(self->values);
+        self->values = NULL;
+    }
+    return 0;
 }
 
 #ifdef PERSISTENT


=== Zope/lib/python/BTrees/Maintainer.txt 1.12 => 1.13 ===
 The C type declaration for keys (e.g., int or PyObject*).
 
+KEY_TYPE_IS_PYOBJECT
+Define if KEY_TYPE is a PyObject*, else undef.
+
 KEY_CHECK(K)
 Tests whether the PyObject* K can be converted to the (C) key type
 (KEY_TYPE).  The macro should return a boolean (zero for false,
@@ -83,6 +86,9 @@
 
 VALUE_TYPE
 The C type declaration for values (e.g., int or PyObject*).
+
+VALUE_TYPE_IS_PYOBJECT
+Define if VALUE_TYPE is a PyObject*, else undef.
 
 TEST_VALUE(X, Y)
 Like Python's cmp().  Compares X to Y, where X & Y are C values of


=== Zope/lib/python/BTrees/_fsBTree.c 1.3 => 1.4 ===
 #define KEYMACROS_H "$Id$\n"
 #define KEY_TYPE char2
+#undef KEY_TYPE_IS_PYOBJECT
 #define KEY_CHECK(K) (PyString_Check(K) && PyString_GET_SIZE(K)==2)
 #define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = ((*(K) < *(T) || (*(K) == *(T) && (K)[1] < (T)[1])) ? -1 : ((*(K) == *(T) && (K)[1] == (T)[1]) ? 0 : 1)) ), 0 )
 #define DECREF_KEY(KEY)
@@ -42,6 +43,7 @@
 /*#include "intvaluemacros.h"*/
 #define VALUEMACROS_H "$Id$\n"
 #define VALUE_TYPE char6
+#undef VALUE_TYPE_IS_PYOBJECT
 #define TEST_VALUE(K, T) strncmp(K,T,6)
 #define DECLARE_VALUE(NAME) VALUE_TYPE NAME
 #define DECREF_VALUE(k)


=== Zope/lib/python/BTrees/intkeymacros.h 1.9 => 1.10 ===
 
 #define KEY_TYPE int
+#undef KEY_TYPE_IS_PYOBJECT
 #define KEY_CHECK PyInt_Check
 #define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) ) , 0 )
 #define DECREF_KEY(KEY)


=== Zope/lib/python/BTrees/intvaluemacros.h 1.7 => 1.8 ===
 
 #define VALUE_TYPE int
+#undef VALUE_TYPE_IS_PYOBJECT
 #define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) 
 #define VALUE_SAME(VALUE, TARGET) ( (VALUE) == (TARGET) )
 #define DECLARE_VALUE(NAME) VALUE_TYPE NAME


=== Zope/lib/python/BTrees/objectkeymacros.h 1.3 => 1.4 ===
 #define KEY_TYPE PyObject *
+#define KEY_TYPE_IS_PYOBJECT
 #define TEST_KEY_SET_OR(V, KEY, TARGET) if ( ( (V) = PyObject_Compare((KEY),(TARGET)) ), PyErr_Occurred() )
 #define INCREF_KEY(k) Py_INCREF(k)
 #define DECREF_KEY(KEY) Py_DECREF(KEY)


=== Zope/lib/python/BTrees/objectvaluemacros.h 1.3 => 1.4 ===
 
 #define VALUE_TYPE PyObject *
+#define VALUE_TYPE_IS_PYOBJECT
 #define TEST_VALUE(VALUE, TARGET) PyObject_Compare((VALUE),(TARGET))
 #define DECLARE_VALUE(NAME) VALUE_TYPE NAME
 #define INCREF_VALUE(k) Py_INCREF(k)