~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_chk_map_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2010-05-11 14:13:31 UTC
  • mto: (5218.2.2 bytes_to_entry_c)
  • mto: This revision was merged to the branch mainline in revision 5225.
  • Revision ID: john@arbash-meinel.com-20100511141331-rizo2ez6bze3ao66
Some small tweaks to the chk_map code.

Find out that we actually weren't using the global definition because we
were assigning inside the if block. So factor that out into a helper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
# cimport all of the definitions we will need to access
56
56
from _static_tuple_c cimport StaticTuple,\
57
57
    import_static_tuple_c, StaticTuple_New, \
58
 
    StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact
 
58
    StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact, \
 
59
    StaticTuple_GET_SIZE
59
60
 
60
61
cdef extern from "_static_tuple_c.h":
61
62
    # Defined explicitly rather than cimport-ing. Trying to use cimport, the
171
172
    return value
172
173
 
173
174
 
 
175
cdef _import_globals():
 
176
    """Set the global attributes. Done lazy to avoid recursive import loops."""
 
177
    global _LeafNode, _InternalNode, _unknown
 
178
 
 
179
    from bzrlib import chk_map
 
180
    _LeafNode = chk_map.LeafNode
 
181
    _InternalNode = chk_map.InternalNode
 
182
    _unknown = chk_map._unknown
 
183
 
 
184
 
174
185
def _deserialise_leaf_node(bytes, key, search_key_func=None):
175
186
    """Deserialise bytes, with key key, into a LeafNode.
176
187
 
188
199
    cdef StaticTuple entry_bits
189
200
 
190
201
    if _LeafNode is None:
191
 
        from bzrlib import chk_map
192
 
        _LeafNode = chk_map.LeafNode
193
 
        _InternalNode = chk_map.InternalNode
194
 
        _unknown = chk_map._unknown
 
202
        _import_globals()
195
203
 
196
204
    result = _LeafNode(search_key_func=search_key_func)
197
205
    # Splitlines can split on '\r' so don't use it, split('\n') adds an
295
303
                                               next_null - entry_start)
296
304
            Py_INCREF(entry)
297
305
            StaticTuple_SET_ITEM(entry_bits, i, entry)
298
 
        if len(entry_bits) != width:
 
306
        if StaticTuple_GET_SIZE(entry_bits) != width:
299
307
            raise AssertionError(
300
308
                'Incorrect number of elements (%d vs %d)'
301
309
                % (len(entry_bits)+1, width + 1))
331
339
    cdef char *prefix, *line_prefix, *next_null, *c_item_prefix
332
340
 
333
341
    if _InternalNode is None:
334
 
        from bzrlib import chk_map
335
 
        _LeafNode = chk_map.LeafNode
336
 
        _InternalNode = chk_map.InternalNode
337
 
        _unknown = chk_map._unknown
 
342
        _import_globals()
338
343
    result = _InternalNode(search_key_func=search_key_func)
339
344
 
340
345
    if not StaticTuple_CheckExact(key):