Rev 4745: Implement the C variant of __iter__ in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple

John Arbash Meinel john at arbash-meinel.com
Fri Oct 2 21:46:30 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple

------------------------------------------------------------
revno: 4745
revision-id: john at arbash-meinel.com-20091002204625-gt2jd8emij2wbw44
parent: john at arbash-meinel.com-20091002203250-q6iv6o2mwjqp4g53
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple
timestamp: Fri 2009-10-02 15:46:25 -0500
message:
  Implement the C variant of __iter__
-------------- next part --------------
=== modified file 'bzrlib/_static_tuple_interned_pyx.pxd'
--- a/bzrlib/_static_tuple_interned_pyx.pxd	2009-10-02 19:59:51 +0000
+++ b/bzrlib/_static_tuple_interned_pyx.pxd	2009-10-02 20:46:25 +0000
@@ -38,3 +38,7 @@
     cpdef int discard(self, key) except -1
     cdef int _insert_clean(self, PyObject *key) except -1
     cpdef Py_ssize_t _resize(self, Py_ssize_t min_unused) except -1
+
+# TODO: might want to export the C api here, though it is all available from
+#       the class object...
+cdef api object StaticTupleInterner_Add(object self, object key)

=== modified file 'bzrlib/_static_tuple_interned_pyx.pyx'
--- a/bzrlib/_static_tuple_interned_pyx.pyx	2009-10-02 20:32:50 +0000
+++ b/bzrlib/_static_tuple_interned_pyx.pyx	2009-10-02 20:46:25 +0000
@@ -517,3 +517,33 @@
     cdef StaticTupleInterner true_self = self
     _check_self_not_none(self)
     return true_self.used
+
+
+# TODO: this should probably have direct tests, since it isn't used by __iter__
+cdef api int StaticTupleInterner_Next(object self, Py_ssize_t *pos,
+                                      PyObject **key):
+    """Walk over items in a StaticTupleInterner.
+
+    :param pos: should be initialized to 0 by the caller, and will be updated
+        by this function
+    :param key: Will return a borrowed reference to key
+    :return: 0 if nothing left, 1 if we are returning a new value
+    """
+    cdef Py_ssize_t i, mask
+    cdef StaticTupleInterner true_self = self
+    cdef PyObject **table
+    _check_self_not_none(self)
+    i = pos[0]
+    if (i < 0):
+        return 0
+    mask = true_self.mask
+    table= true_self.table
+    while (i <= mask and (table[i] == NULL or table[i] == _dummy)):
+        i += 1
+    pos[0] = i + 1
+    if (i > mask):
+        return 0 # All done
+    if (key != NULL):
+        key[0] = table[i]
+    return 1
+



More information about the bazaar-commits mailing list