~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/graph.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-15 17:44:41 UTC
  • mfrom: (3224.1.29 annotate_finish)
  • Revision ID: pqm@pqm.ubuntu.com-20080315174441-l8xpw6femn0syal1
(jam) Tweak annotate performance for pack repositories,
        improving speed and decreasing memory consumption.

Show diffs side-by-side

added added

removed removed

Lines of Context:
473
473
            return set(heads)
474
474
 
475
475
 
 
476
class FrozenHeadsCache(object):
 
477
    """Cache heads() calls, assuming the caller won't modify them."""
 
478
 
 
479
    def __init__(self, graph):
 
480
        self.graph = graph
 
481
        self._heads = {}
 
482
 
 
483
    def heads(self, keys):
 
484
        """Return the heads of keys.
 
485
 
 
486
        Similar to Graph.heads(). The main difference is that the return value
 
487
        is a frozen set which cannot be mutated.
 
488
 
 
489
        :see also: Graph.heads.
 
490
        :param keys: The keys to calculate heads for.
 
491
        :return: A frozenset containing the heads.
 
492
        """
 
493
        keys = frozenset(keys)
 
494
        try:
 
495
            return self._heads[keys]
 
496
        except KeyError:
 
497
            heads = frozenset(self.graph.heads(keys))
 
498
            self._heads[keys] = heads
 
499
            return heads
 
500
 
 
501
    def cache(self, keys, heads):
 
502
        """Store a known value."""
 
503
        self._heads[frozenset(keys)] = frozenset(heads)
 
504
 
 
505
 
476
506
class _BreadthFirstSearcher(object):
477
507
    """Parallel search breadth-first the ancestry of revisions.
478
508