~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_btree_serializer_py.py

  • Committer: Vincent Ladeuil
  • Date: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""B+Tree index parsing."""
19
19
 
 
20
from bzrlib import static_tuple
 
21
 
 
22
 
20
23
def _parse_leaf_lines(bytes, key_length, ref_list_length):
21
24
    lines = bytes.split('\n')
22
25
    nodes = []
 
26
    as_st = static_tuple.StaticTuple.from_sequence
 
27
    stuple = static_tuple.StaticTuple
23
28
    for line in lines[1:]:
24
29
        if line == '':
25
30
            return nodes
26
31
        elements = line.split('\0', key_length)
27
32
        # keys are tuples
28
 
        key = tuple(elements[:key_length])
 
33
        key = as_st(elements[:key_length]).intern()
29
34
        line = elements[-1]
30
35
        references, value = line.rsplit('\0', 1)
31
36
        if ref_list_length:
32
37
            ref_lists = []
33
38
            for ref_string in references.split('\t'):
34
 
                ref_lists.append(tuple([
35
 
                    tuple(ref.split('\0')) for ref in ref_string.split('\r') if ref
36
 
                    ]))
37
 
            ref_lists = tuple(ref_lists)
38
 
            node_value = (value, ref_lists)
 
39
                ref_list = as_st([as_st(ref.split('\0')).intern()
 
40
                                  for ref in ref_string.split('\r') if ref])
 
41
                ref_lists.append(ref_list)
 
42
            ref_lists = as_st(ref_lists)
 
43
            node_value = stuple(value, ref_lists)
39
44
        else:
40
 
            node_value = (value, ())
 
45
            node_value = stuple(value, stuple())
 
46
        # No need for StaticTuple here as it is put into a dict
41
47
        nodes.append((key, node_value))
42
48
    return nodes
43
49