~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/chk_map.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-21 13:36:51 UTC
  • mfrom: (5243.2.1 readdir_cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100521133651-p62dndo2giy5ls21
(lifeless) Some cleanups to the readdir pyrex code for a little efficiency
 and to avoid compile warnings. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
44
44
lazy_import.lazy_import(globals(), """
45
45
from bzrlib import (
46
46
    errors,
 
47
    versionedfile,
47
48
    )
48
49
""")
49
50
from bzrlib import (
50
 
    errors,
51
51
    lru_cache,
52
52
    osutils,
53
53
    registry,
90
90
_INTERESTING_NEW_SIZE = 50
91
91
# If a ChildNode shrinks by more than this amount, we check for a remap
92
92
_INTERESTING_SHRINKAGE_LIMIT = 20
 
93
# If we delete more than this many nodes applying a delta, we check for a remap
 
94
_INTERESTING_DELETES_LIMIT = 5
93
95
 
94
96
 
95
97
def _search_key_plain(key):
133
135
            into the map; if old_key is not None, then the old mapping
134
136
            of old_key is removed.
135
137
        """
136
 
        has_deletes = False
 
138
        delete_count = 0
137
139
        # Check preconditions first.
138
140
        as_st = StaticTuple.from_sequence
139
141
        new_items = set([as_st(key) for (old, key, value) in delta
146
148
        for old, new, value in delta:
147
149
            if old is not None and old != new:
148
150
                self.unmap(old, check_remap=False)
149
 
                has_deletes = True
 
151
                delete_count += 1
150
152
        for old, new, value in delta:
151
153
            if new is not None:
152
154
                self.map(new, value)
153
 
        if has_deletes:
 
155
        if delete_count > _INTERESTING_DELETES_LIMIT:
 
156
            trace.mutter("checking remap as %d deletions", delete_count)
154
157
            self._check_remap()
155
158
        return self._save()
156
159
 
570
573
        """Check if nodes can be collapsed."""
571
574
        self._ensure_root()
572
575
        if type(self._root_node) is InternalNode:
573
 
            self._root_node = self._root_node._check_remap(self._store)
 
576
            self._root_node._check_remap(self._store)
574
577
 
575
578
    def _save(self):
576
579
        """Save the map completely.
1369
1372
        return self._search_prefix
1370
1373
 
1371
1374
    def unmap(self, store, key, check_remap=True):
1372
 
        """Remove key from this node and its children."""
 
1375
        """Remove key from this node and it's children."""
1373
1376
        if not len(self._items):
1374
1377
            raise AssertionError("can't unmap in an empty InternalNode.")
1375
1378
        children = [node for node, _