Rev 4765: Merge the 2.1-static-tuple-no-use branch, but restore the in http://bazaar.launchpad.net/~jameinel/bzr/2.1-static-tuple-btree

John Arbash Meinel john at arbash-meinel.com
Thu Oct 8 16:46:13 BST 2009


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

------------------------------------------------------------
revno: 4765 [merge]
revision-id: john at arbash-meinel.com-20091008154441-7rta5brpdwsgww2b
parent: john at arbash-meinel.com-20091008041043-579p0as1c3xq1q6w
parent: john at arbash-meinel.com-20091008145954-v365z5qkqi6eghpd
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple-btree
timestamp: Thu 2009-10-08 10:44:41 -0500
message:
  Merge the 2.1-static-tuple-no-use branch, but restore the
  functionality to btree that involves using StaticTuple instead of tuple().
  At this point, I'm leaving out the changes to string interning, as that
  can easily be considered a separate patch.
modified:
  bzrlib/_btree_serializer_pyx.pyx _parse_btree_c.pyx-20080703034413-3q25bklkenti3p8p-2
  bzrlib/_chk_map_py.py          _chk_map_py.py-20090309114220-1kurz7oez2gwqtcf-1
  bzrlib/_chk_map_pyx.pyx        _chk_map_pyx.pyx-20090309111231-peyz7p2azr0dzdrb-1
  bzrlib/_simple_set_pyx.pxd     _static_tuple_intern-20091002191442-ix6rkqbw8ktoj7r5-1
  bzrlib/_simple_set_pyx.pyx     _static_tuple_intern-20091002053806-sid67p8spedru51w-1
  bzrlib/chk_map.py              chk_map.py-20081001014447-ue6kkuhofvdecvxa-1
  bzrlib/tests/test__simple_set.py test__static_tuple_i-20091002053806-sid67p8spedru51w-2
  bzrlib/tests/test_chk_map.py   test_chk_map.py-20081001014447-ue6kkuhofvdecvxa-2
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx	2009-10-08 04:10:43 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx	2009-10-08 15:44:41 +0000
@@ -104,8 +104,6 @@
     return result
 
 from bzrlib import _static_tuple_c
-cdef object _ST
-_ST = _static_tuple_c.StaticTuple
 # This sets up the StaticTuple C_API functionality
 import_static_tuple_c()
 
@@ -159,7 +157,7 @@
         cdef char *temp_ptr
         cdef int loop_counter
         cdef StaticTuple key
-        
+
         key = StaticTuple_New(self.key_length)
         for loop_counter from 0 <= loop_counter < self.key_length:
             # grab a key segment
@@ -175,13 +173,7 @@
                                                    last - self._start)))
                     raise AssertionError(failure_string)
             # capture the key string
-            if (self.key_length == 1 
-                and (temp_ptr - self._start) == 45
-                and strncmp(self._start, 'sha1:', 5) == 0):
-                key_element = safe_string_from_size(self._start,
-                                                    temp_ptr - self._start)
-            else:
-                key_element = safe_interned_string_from_size(self._start,
+            key_element = safe_interned_string_from_size(self._start,
                                                          temp_ptr - self._start)
             # advance our pointer
             self._start = temp_ptr + 1
@@ -197,7 +189,6 @@
         cdef char *ref_ptr
         cdef char *next_start
         cdef int loop_counter
-        cdef Py_ssize_t str_len
 
         self._start = self._cur_str
         # Find the next newline
@@ -233,20 +224,8 @@
             # Invalid line
             raise AssertionError("Failed to find the value area")
         else:
-            # Because of how conversions were done, we ended up with *lots* of
-            # values that are identical. These are all of the 0-length nodes
-            # that are referred to by the TREE_ROOT (and likely some other
-            # directory nodes.) For example, bzr has 25k references to
-            # something like '12607215 328306 0 0', which ends up consuming 1MB
-            # of memory, just for those strings.
-            str_len = last - temp_ptr - 1
-            if (str_len > 4
-                and strncmp(" 0 0", last - 4, 4) == 0):
-                # This drops peak mem for bzr.dev from 87.4MB => 86.2MB
-                # For Launchpad 236MB => 232MB
-                value = safe_interned_string_from_size(temp_ptr + 1, str_len)
-            else:
-                value = safe_string_from_size(temp_ptr + 1, str_len)
+            # capture the value string
+            value = safe_string_from_size(temp_ptr + 1, last - temp_ptr - 1)
             # shrink the references end point
             last = temp_ptr
 
@@ -283,7 +262,7 @@
                     if temp_ptr == NULL:
                         # key runs to the end
                         temp_ptr = ref_ptr
-                                        
+
                     PyList_Append(ref_list, self.extract_key(temp_ptr))
                 ref_list = StaticTuple_Intern(StaticTuple(*ref_list))
                 Py_INCREF(ref_list)

=== modified file 'bzrlib/_chk_map_py.py'
--- a/bzrlib/_chk_map_py.py	2009-09-30 21:53:59 +0000
+++ b/bzrlib/_chk_map_py.py	2009-10-08 04:35:01 +0000
@@ -156,5 +156,3 @@
     result._search_prefix = common_prefix
     return result
 
-
-_key_type = tuple

=== modified file 'bzrlib/_chk_map_pyx.pyx'
--- a/bzrlib/_chk_map_pyx.pyx	2009-10-07 18:53:41 +0000
+++ b/bzrlib/_chk_map_pyx.pyx	2009-10-08 04:35:01 +0000
@@ -59,21 +59,9 @@
 
     uLong crc32(uLong crc, Bytef *buf, uInt len)
 
-# It seems we need to import the definitions so that the pyrex compiler has
-# local names to access them.
-from _static_tuple_c cimport StaticTuple,\
-    import_static_tuple_c, StaticTuple_New, \
-    StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact
-
-
-# This sets up the StaticTuple C_API functionality
-import_static_tuple_c()
-
-cdef object _LeafNode
+
 _LeafNode = None
-cdef object _InternalNode
 _InternalNode = None
-cdef object _unknown
 _unknown = None
 
 # We shouldn't just copy this from _dirstate_helpers_pyx
@@ -101,11 +89,11 @@
     cdef uInt crc_val
     cdef Py_ssize_t out_off
     cdef char *c_out
-    # cdef PyObject *bit
+    cdef PyObject *bit
 
-    if not PyTuple_CheckExact(key) and not StaticTuple_CheckExact(key):
+    if not PyTuple_CheckExact(key):
         raise TypeError('key %r is not a tuple' % (key,))
-    num_bits = len(key)
+    num_bits = PyTuple_GET_SIZE(key)
     # 4 bytes per crc32, and another 1 byte between bits
     num_out_bytes = (9 * num_bits) - 1
     out = PyString_FromStringAndSize(NULL, num_out_bytes)
@@ -117,13 +105,11 @@
         # We use the _ptr variant, because GET_ITEM returns a borrowed
         # reference, and Pyrex assumes that returned 'object' are a new
         # reference
-        # XXX: This needs to be updated for PySequence_GetItem since both
-        #      PyTuple and StaticTuple support that api
-        bit = key[i]# PyTuple_GET_ITEM_ptr(key, i)
-        if not PyString_CheckExact(bit):
+        bit = PyTuple_GET_ITEM_ptr(key, i)
+        if not PyString_CheckExact_ptr(bit):
             raise TypeError('Bit %d of %r is not a string' % (i, key))
-        c_bit = <Bytef *>PyString_AS_STRING(bit)
-        c_len = PyString_GET_SIZE(bit)
+        c_bit = <Bytef *>PyString_AS_STRING_ptr(bit)
+        c_len = PyString_GET_SIZE_ptr(bit)
         crc_val = crc32(0, c_bit, c_len)
         # Hex(val) order
         sprintf(c_out, '%08X', crc_val)
@@ -141,11 +127,11 @@
     cdef uInt crc_val
     cdef Py_ssize_t out_off
     cdef char *c_out
-    # cdef PyObject *bit
+    cdef PyObject *bit
 
-    if not PyTuple_CheckExact(key) and not StaticTuple_CheckExact(key):
+    if not PyTuple_CheckExact(key):
         raise TypeError('key %r is not a tuple' % (key,))
-    num_bits = len(key)
+    num_bits = PyTuple_GET_SIZE(key)
     # 4 bytes per crc32, and another 1 byte between bits
     num_out_bytes = (5 * num_bits) - 1
     out = PyString_FromStringAndSize(NULL, num_out_bytes)
@@ -154,12 +140,12 @@
         if i > 0:
             c_out[0] = c'\x00'
             c_out = c_out + 1
-        bit = key[i] # PyTuple_GET_ITEM_ptr(key, i)
-        if not PyString_CheckExact(bit):
+        bit = PyTuple_GET_ITEM_ptr(key, i)
+        if not PyString_CheckExact_ptr(bit):
             raise TypeError('Bit %d of %r is not a string: %r' % (i, key,
-            bit))
-        c_bit = <Bytef *>PyString_AS_STRING(bit)
-        c_len = PyString_GET_SIZE(bit)
+            <object>bit))
+        c_bit = <Bytef *>PyString_AS_STRING_ptr(bit)
+        c_len = PyString_GET_SIZE_ptr(bit)
         crc_val = crc32(0, c_bit, c_len)
         # MSB order
         c_out[0] = (crc_val >> 24) & 0xFF
@@ -209,7 +195,6 @@
     cdef char *prefix, *value_start, *prefix_tail
     cdef char *next_null, *last_null, *line_start
     cdef char *c_entry, *entry_start
-    cdef StaticTuple entry_bits
 
     if _LeafNode is None:
         from bzrlib import chk_map
@@ -280,12 +265,12 @@
             if next_line == NULL:
                 raise ValueError('missing trailing newline')
             cur = next_line + 1
-        entry_bits = StaticTuple_New(width)
+        entry_bits = PyTuple_New(width)
         for i from 0 <= i < num_prefix_bits:
             entry = prefix_bits[i]
             # SET_ITEM 'steals' a reference
             Py_INCREF(entry)
-            StaticTuple_SET_ITEM(entry_bits, i, entry)
+            PyTuple_SET_ITEM(entry_bits, i, entry)
         value = PyString_FromStringAndSize(value_start, next_line - value_start)
         # The next entry bit needs the 'tail' from the prefix, and first part
         # of the line
@@ -303,7 +288,7 @@
             memcpy(c_entry + prefix_tail_len, line_start, next_null - line_start)
         Py_INCREF(entry)
         i = num_prefix_bits
-        StaticTuple_SET_ITEM(entry_bits, i, entry)
+        PyTuple_SET_ITEM(entry_bits, i, entry)
         while next_null != last_null: # We have remaining bits
             i = i + 1
             if i > width:
@@ -316,12 +301,11 @@
             entry = PyString_FromStringAndSize(entry_start,
                                                next_null - entry_start)
             Py_INCREF(entry)
-            StaticTuple_SET_ITEM(entry_bits, i, entry)
+            PyTuple_SET_ITEM(entry_bits, i, entry)
         if len(entry_bits) != width:
             raise AssertionError(
                 'Incorrect number of elements (%d vs %d)'
                 % (len(entry_bits)+1, width + 1))
-        entry_bits = StaticTuple_Intern(entry_bits)
         PyDict_SetItem(items, entry_bits, value)
     if len(items) != length:
         raise ValueError("item count (%d) mismatch for key %s,"
@@ -400,8 +384,7 @@
         memcpy(c_item_prefix + prefix_length, cur, next_null - cur)
         flat_key = PyString_FromStringAndSize(next_null + 1,
                                               next_line - next_null - 1)
-        flat_key = StaticTuple(flat_key).intern()
-        PyDict_SetItem(items, item_prefix, flat_key)
+        PyDict_SetItem(items, item_prefix, (flat_key,))
         cur = next_line + 1
     assert len(items) > 0
     result._items = items
@@ -416,5 +399,3 @@
     result._search_prefix = PyString_FromStringAndSize(prefix, prefix_length)
     return result
 
-
-_key_type = StaticTuple

=== modified file 'bzrlib/_simple_set_pyx.pxd'
--- a/bzrlib/_simple_set_pyx.pxd	2009-10-07 19:31:39 +0000
+++ b/bzrlib/_simple_set_pyx.pxd	2009-10-08 04:40:16 +0000
@@ -27,6 +27,7 @@
     ctypedef struct PyObject:
         pass
 
+
 cdef public api class SimpleSet [object SimpleSetObject, type SimpleSet_Type]:
     """A class similar to PySet, but with simpler implementation.
 
@@ -53,7 +54,14 @@
     cdef int _insert_clean(self, PyObject *key) except -1
     cdef 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 SimpleSet_Add(object self, object key)
 cdef api SimpleSet SimpleSet_New()
+cdef api object SimpleSet_Add(object self, object key)
+cdef api int SimpleSet_Contains(object self, object key) except -1
+cdef api int SimpleSet_Discard(object self, object key) except -1
+cdef api PyObject *SimpleSet_Get(SimpleSet self, object key) except? NULL
+cdef api Py_ssize_t SimpleSet_Size(object self) except -1
+cdef api int SimpleSet_Next(object self, Py_ssize_t *pos, PyObject **key)

=== modified file 'bzrlib/_simple_set_pyx.pyx'
--- a/bzrlib/_simple_set_pyx.pyx	2009-10-07 21:17:47 +0000
+++ b/bzrlib/_simple_set_pyx.pyx	2009-10-08 04:40:16 +0000
@@ -38,6 +38,7 @@
     void PyMem_Free(void *)
     void memset(void *, int, size_t)
 
+
 cdef object _dummy_obj
 cdef PyObject *_dummy
 _dummy_obj = object()

=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2009-10-07 19:35:09 +0000
+++ b/bzrlib/chk_map.py	2009-10-08 04:35:01 +0000
@@ -133,7 +133,7 @@
 
     def _ensure_root(self):
         """Ensure that the root node is an object not a key."""
-        if type(self._root_node) in (_key_type, tuple):
+        if type(self._root_node) is tuple:
             # Demand-load the root
             self._root_node = self._get_node(self._root_node)
 
@@ -147,7 +147,7 @@
         :param node: A tuple key or node object.
         :return: A node object.
         """
-        if type(node) in (tuple, _key_type):
+        if type(node) is tuple:
             bytes = self._read_bytes(node)
             return _deserialise(bytes, node,
                 search_key_func=self._search_key_func)
@@ -194,7 +194,7 @@
             for key, value in sorted(node._items.iteritems()):
                 # Don't use prefix nor indent here to line up when used in
                 # tests in conjunction with assertEqualDiff
-                result.append('      %r %r' % (tuple(key), value))
+                result.append('      %r %r' % (key, value))
         return result
 
     @classmethod
@@ -486,7 +486,7 @@
 
     def key(self):
         """Return the key for this map."""
-        if type(self._root_node) in (tuple, _key_type):
+        if type(self._root_node) is tuple:
             return self._root_node
         else:
             return self._root_node._key
@@ -516,7 +516,7 @@
 
     def _node_key(self, node):
         """Get the key for a node whether it's a tuple or node."""
-        if type(node) in (tuple, _key_type):
+        if type(node) is tuple:
             return node
         else:
             return node._key
@@ -542,7 +542,7 @@
 
         :return: The key of the root node.
         """
-        if type(self._root_node) in (tuple, _key_type):
+        if type(self._root_node) is tuple:
             # Already saved.
             return self._root_node
         keys = list(self._root_node.serialise(self._store))
@@ -1024,7 +1024,7 @@
             # for whatever we are missing
             shortcut = True
             for prefix, node in self._items.iteritems():
-                if node.__class__ in (tuple, _key_type):
+                if node.__class__ is tuple:
                     keys[node] = (prefix, None)
                 else:
                     yield node, None
@@ -1059,7 +1059,7 @@
                     # A given key can only match 1 child node, if it isn't
                     # there, then we can just return nothing
                     return
-                if node.__class__ in (tuple, _key_type):
+                if node.__class__ is tuple:
                     keys[node] = (search_prefix, [key])
                 else:
                     # This is loaded, and the only thing that can match,
@@ -1092,7 +1092,7 @@
                         # We can ignore this one
                         continue
                     node_key_filter = prefix_to_keys[search_prefix]
-                    if node.__class__ in (tuple, _key_type):
+                    if node.__class__ is tuple:
                         keys[node] = (search_prefix, node_key_filter)
                     else:
                         yield node, node_key_filter
@@ -1107,7 +1107,7 @@
                         if sub_prefix in length_filter:
                             node_key_filter.extend(prefix_to_keys[sub_prefix])
                     if node_key_filter: # this key matched something, yield it
-                        if node.__class__ in (tuple, _key_type):
+                        if node.__class__ is tuple:
                             keys[node] = (prefix, node_key_filter)
                         else:
                             yield node, node_key_filter
@@ -1245,7 +1245,7 @@
         :return: An iterable of the keys inserted by this operation.
         """
         for node in self._items.itervalues():
-            if type(node) in (tuple, _key_type):
+            if type(node) is tuple:
                 # Never deserialised.
                 continue
             if node._key is not None:
@@ -1262,7 +1262,7 @@
         lines.append('%s\n' % (self._search_prefix,))
         prefix_len = len(self._search_prefix)
         for prefix, node in sorted(self._items.items()):
-            if type(node) in (tuple, _key_type):
+            if type(node) is tuple:
                 key = node[0]
             else:
                 key = node._key[0]
@@ -1307,7 +1307,7 @@
             raise AssertionError("unserialised nodes have no refs.")
         refs = []
         for value in self._items.itervalues():
-            if type(value) in (tuple, _key_type):
+            if type(value) is tuple:
                 refs.append(value)
             else:
                 refs.append(value.key())
@@ -1639,7 +1639,6 @@
         _search_key_255,
         _deserialise_leaf_node,
         _deserialise_internal_node,
-        _key_type,
         )
 except ImportError, e:
     osutils.failed_to_load_extension(e)
@@ -1648,7 +1647,6 @@
         _search_key_255,
         _deserialise_leaf_node,
         _deserialise_internal_node,
-        _key_type,
         )
 search_key_registry.register('hash-16-way', _search_key_16)
 search_key_registry.register('hash-255-way', _search_key_255)

=== modified file 'bzrlib/tests/test__simple_set.py'
--- a/bzrlib/tests/test__simple_set.py	2009-10-07 19:31:39 +0000
+++ b/bzrlib/tests/test__simple_set.py	2009-10-08 04:35:01 +0000
@@ -24,39 +24,32 @@
     tests,
     )
 
-from bzrlib.tests import (
-    test__static_tuple,
-    )
-try:
-    from bzrlib import _simple_set_pyx as _module
-except ImportError:
-    _module = None
-try:
-    from bzrlib._static_tuple_c import StaticTuple
-except ImportError:
-    from bzrlib._static_tuple_py import StaticTuple
+try:
+    from bzrlib import _simple_set_pyx
+except ImportError:
+    _simple_set_pyx = None
 
 
 # Even though this is an extension, we don't permute the tests for a python
 # version. As the plain python version is just a dict or set
 
-class _CompiledStaticTupleInterned(tests.Feature):
+class _CompiledSimpleSet(tests.Feature):
 
     def _probe(self):
-        if _module is None:
+        if _simple_set_pyx is None:
             return False
         return True
 
     def feature_name(self):
         return 'bzrlib._simple_set_pyx'
 
-CompiledStaticTupleInterned = _CompiledStaticTupleInterned()
-
-
-class TestStaticTupleInterned(tests.TestCase):
-
-    _test_needs_features = [CompiledStaticTupleInterned, 
-                            test__static_tuple.CompiledStaticTuple]
+CompiledSimpleSet = _CompiledSimpleSet()
+
+
+class TestSimpleSet(tests.TestCase):
+
+    _test_needs_features = [CompiledSimpleSet]
+    module = _simple_set_pyx
 
     def assertIn(self, obj, container):
         self.assertTrue(obj in container,
@@ -76,17 +69,15 @@
         assertRefcount actually creates a new pointer, as does calling
         sys.getrefcount. So pass the expected value *before* the call.
         """
-        # I don't understand why it is count+3 here, but it seems to be
-        # correct. If I check in the calling function, with:
-        # self.assertEqual(count+1, sys.getrefcount(obj))
-        # Then it works fine. Something about passing it to assertRefcount is
-        # actually double-incrementing (and decrementing) the refcount
-        self.assertEqual(count+3, sys.getrefcount(obj))
+        # I'm not sure why the offset is 3, but I've check that in the caller,
+        # an offset of 1 works, which is expected. Not sure why assertRefcount
+        # is incrementing/decrementing 2 times
+        self.assertEqual(count, sys.getrefcount(obj)-3)
 
     def test_initial(self):
-        obj = _module.SimpleSet()
+        obj = self.module.SimpleSet()
         self.assertEqual(0, len(obj))
-        st = StaticTuple('foo', 'bar')
+        st = ('foo', 'bar')
         self.assertFillState(0, 0, 0x3ff, obj)
 
     def test__lookup(self):
@@ -98,23 +89,23 @@
         #  ('a', 'a'), ('f', '4'), ('p', 'r'), ('q', '1'), ('F', 'T'),
         #  ('Q', 'Q'), ('V', 'd'), ('7', 'C')
         # all collide @ 643
-        obj = _module.SimpleSet()
-        offset, val = obj._test_lookup(StaticTuple('a', 'a'))
-        self.assertEqual(643, offset)
-        self.assertEqual('<null>', val)
-        offset, val = obj._test_lookup(StaticTuple('f', '4'))
-        self.assertEqual(643, offset)
-        self.assertEqual('<null>', val)
-        offset, val = obj._test_lookup(StaticTuple('p', 'r'))
+        obj = self.module.SimpleSet()
+        offset, val = obj._test_lookup(('a', 'a'))
+        self.assertEqual(643, offset)
+        self.assertEqual('<null>', val)
+        offset, val = obj._test_lookup(('f', '4'))
+        self.assertEqual(643, offset)
+        self.assertEqual('<null>', val)
+        offset, val = obj._test_lookup(('p', 'r'))
         self.assertEqual(643, offset)
         self.assertEqual('<null>', val)
 
     def test_get_set_del_with_collisions(self):
-        obj = _module.SimpleSet()
-        k1 = StaticTuple('a', 'a')
-        k2 = StaticTuple('f', '4') # collides
-        k3 = StaticTuple('p', 'r')
-        k4 = StaticTuple('q', '1')
+        obj = self.module.SimpleSet()
+        k1 = ('a', 'a')
+        k2 = ('f', '4') # collides
+        k3 = ('p', 'r')
+        k4 = ('q', '1')
         self.assertEqual((643, '<null>'), obj._test_lookup(k1))
         self.assertEqual((643, '<null>'), obj._test_lookup(k2))
         self.assertEqual((643, '<null>'), obj._test_lookup(k3))
@@ -160,9 +151,12 @@
         self.assertNotIn(k4, obj)
 
     def test_add(self):
-        obj = _module.SimpleSet()
+        obj = self.module.SimpleSet()
         self.assertFillState(0, 0, 0x3ff, obj)
-        k1 = StaticTuple('foo')
+        # We use this clumsy notation, because otherwise the refcounts are off.
+        # I'm guessing the python compiler sees it is a static tuple, and adds
+        # it to the function variables, or somesuch
+        k1 = tuple(['foo'])
         self.assertRefcount(1, k1)
         self.assertIs(k1, obj.add(k1))
         self.assertFillState(1, 1, 0x3ff, obj)
@@ -172,7 +166,7 @@
         self.assertIs(k1, ktest)
         del ktest
         self.assertRefcount(2, k1)
-        k2 = StaticTuple('foo')
+        k2 = tuple(['foo'])
         self.assertRefcount(1, k2)
         self.assertIsNot(k1, k2)
         # doesn't add anything, so the counters shouldn't be adjusted
@@ -188,7 +182,7 @@
         del obj[k1]
         self.assertFillState(0, 1, 0x3ff, obj)
         self.assertRefcount(1, k1)
-        k3 = StaticTuple('bar')
+        k3 = tuple(['bar'])
         self.assertRefcount(1, k3)
         self.assertIs(k3, obj.add(k3))
         self.assertFillState(1, 2, 0x3ff, obj)
@@ -200,10 +194,10 @@
         self.assertRefcount(2, k3)
 
     def test_discard(self):
-        obj = _module.SimpleSet()
-        k1 = StaticTuple('foo')
-        k2 = StaticTuple('foo')
-        k3 = StaticTuple('bar')
+        obj = self.module.SimpleSet()
+        k1 = tuple(['foo'])
+        k2 = tuple(['foo'])
+        k3 = tuple(['bar'])
         self.assertRefcount(1, k1)
         self.assertRefcount(1, k2)
         self.assertRefcount(1, k3)
@@ -217,10 +211,10 @@
         self.assertRefcount(1, k3)
 
     def test__delitem__(self):
-        obj = _module.SimpleSet()
-        k1 = StaticTuple('foo')
-        k2 = StaticTuple('foo')
-        k3 = StaticTuple('bar')
+        obj = self.module.SimpleSet()
+        k1 = tuple(['foo'])
+        k2 = tuple(['foo'])
+        k3 = tuple(['bar'])
         self.assertRefcount(1, k1)
         self.assertRefcount(1, k2)
         self.assertRefcount(1, k3)
@@ -234,10 +228,10 @@
         self.assertRefcount(1, k3)
 
     def test__resize(self):
-        obj = _module.SimpleSet()
-        k1 = StaticTuple('foo')
-        k2 = StaticTuple('bar')
-        k3 = StaticTuple('baz')
+        obj = self.module.SimpleSet()
+        k1 = ('foo',)
+        k2 = ('bar',)
+        k3 = ('baz',)
         obj.add(k1)
         obj.add(k2)
         obj.add(k3)
@@ -264,18 +258,18 @@
         self.assertEqual((591, '<null>'), obj._test_lookup(k2))
 
     def test_add_and_remove_lots_of_items(self):
-        obj = _module.SimpleSet()
+        obj = self.module.SimpleSet()
         chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
         for i in chars:
             for j in chars:
-                k = StaticTuple(i, j)
+                k = (i, j)
                 obj.add(k)
         num = len(chars)*len(chars)
         self.assertFillState(num, num, 0x1fff, obj)
         # Now delete all of the entries and it should shrink again
         for i in chars:
             for j in chars:
-                k = StaticTuple(i, j)
+                k = (i, j)
                 obj.discard(k)
         # It should be back to 1024 wide mask, though there may still be some
         # dummy values in there
@@ -284,10 +278,10 @@
         self.assertTrue(obj.fill < 1024 / 5)
 
     def test__iter__(self):
-        obj = _module.SimpleSet()
-        k1 = StaticTuple('1')
-        k2 = StaticTuple('1', '2')
-        k3 = StaticTuple('3', '4')
+        obj = self.module.SimpleSet()
+        k1 = ('1',)
+        k2 = ('1', '2')
+        k3 = ('3', '4')
         obj.add(k1)
         obj.add(k2)
         obj.add(k3)
@@ -297,7 +291,7 @@
         self.assertEqual(sorted([k1, k2, k3]), sorted(all))
         iterator = iter(obj)
         iterator.next()
-        obj.add(StaticTuple('foo'))
+        obj.add(('foo',))
         # Set changed size
         self.assertRaises(RuntimeError, iterator.next)
         # And even removing an item still causes it to fail

=== modified file 'bzrlib/tests/test_chk_map.py'
--- a/bzrlib/tests/test_chk_map.py	2009-09-30 21:53:59 +0000
+++ b/bzrlib/tests/test_chk_map.py	2009-10-08 04:35:01 +0000
@@ -831,13 +831,13 @@
         # 'ab' and 'ac' nodes
         chkmap.map(('aad',), 'v')
         self.assertIsInstance(chkmap._root_node._items['aa'], InternalNode)
-        self.assertIsInstance(chkmap._root_node._items['ab'], (tuple, chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['ac'], (tuple, chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['ab'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['ac'], tuple)
         # Unmapping 'acd' can notice that 'aa' is an InternalNode and not have
         # to map in 'ab'
         chkmap.unmap(('acd',))
         self.assertIsInstance(chkmap._root_node._items['aa'], InternalNode)
-        self.assertIsInstance(chkmap._root_node._items['ab'], (tuple, chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['ab'], tuple)
 
     def test_unmap_without_fitting_doesnt_page_in(self):
         store = self.get_chk_bytes()
@@ -860,9 +860,8 @@
         chkmap.map(('aaf',), 'v')
         # At this point, the previous nodes should not be paged in, but the
         # newly added nodes would be
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple, chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
@@ -870,8 +869,8 @@
         # Now unmapping one of the new nodes will use only the already-paged-in
         # nodes to determine that we don't need to do more.
         chkmap.unmap(('aaf',))
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple, chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple, chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
@@ -898,12 +897,9 @@
         chkmap.map(('aad',), 'v')
         # At this point, the previous nodes should not be paged in, but the
         # newly added node would be
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
-        chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
         # Unmapping the new node will check the existing nodes to see if they
         # would fit.
@@ -941,12 +937,9 @@
         chkmap.map(('aad',), 'v')
         # At this point, the previous nodes should not be paged in, but the
         # newly added node would be
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
-        chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
         # Now clear the page cache, and only include 2 of the children in the
         # cache
@@ -961,8 +954,7 @@
         # Unmapping the new node will check the nodes from the page cache
         # first, and not have to read in 'aaa'
         chkmap.unmap(('aad',))
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
-        chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aab'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
 
@@ -982,12 +974,9 @@
         chkmap.map(('aaf',), 'val')
         # At this point, the previous nodes should not be paged in, but the
         # newly added node would be
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
-        chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aaf'], LeafNode)
@@ -995,12 +984,9 @@
         # Unmapping a new node will see the other nodes that are already in
         # memory, and not need to page in anything else
         chkmap.unmap(('aad',))
-        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
-        chk_map._key_type))
-        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
-        chk_map._key_type))
+        self.assertIsInstance(chkmap._root_node._items['aaa'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aab'], tuple)
+        self.assertIsInstance(chkmap._root_node._items['aac'], tuple)
         self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
         self.assertIsInstance(chkmap._root_node._items['aaf'], LeafNode)
 
@@ -1045,8 +1031,8 @@
             {('a',): 'content here', ('b',): 'more content'},
             chk_bytes=basis._store, maximum_size=10)
         list(target.iter_changes(basis))
-        self.assertIsInstance(target._root_node, (tuple, chk_map._key_type))
-        self.assertIsInstance(basis._root_node, (tuple, chk_map._key_type))
+        self.assertIsInstance(target._root_node, tuple)
+        self.assertIsInstance(basis._root_node, tuple)
 
     def test_iter_changes_ab_ab_changed_values_shown(self):
         basis = self._get_map({('a',): 'content here', ('b',): 'more content'},
@@ -1946,7 +1932,7 @@
         # Ensure test validity: nothing paged in below the root.
         self.assertEqual(2,
             len([value for value in node._items.values()
-                if type(value) in (tuple, chk_map._key_type)]))
+                if type(value) == tuple]))
         # now, mapping to k3 should add a k3 leaf
         prefix, nodes = node.map(None, ('k3',), 'quux')
         self.assertEqual("k", prefix)
@@ -1985,7 +1971,7 @@
         # Ensure test validity: nothing paged in below the root.
         self.assertEqual(2,
             len([value for value in node._items.values()
-                if type(value) in (tuple, chk_map._key_type)]))
+                if type(value) == tuple]))
         # now, mapping to k23 causes k22 ('k2' in node) to split into k22 and
         # k23, which for simplicity in the current implementation generates
         # a new internal node between node, and k22/k23.



More information about the bazaar-commits mailing list