1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
=== modified file 'bzrlib/weave.py'
--- bzrlib/weave.py
+++ bzrlib/weave.py
@@ -83,6 +83,10 @@
# TODO: Perhaps the API should work only in names to hide the integer
# indexes from the user?
+
+# TODO: Is there any potential performance win by having an add()
+# variant that is passed a pre-cooked version of the single basis
+# version?
@@ -191,8 +195,8 @@
Set by read_weave.
"""
- __slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
- '_weave_name']
+ ##__slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
+ ## '_weave_name', '_inclusion_cache']
def __init__(self, weave_name=None):
self._weave = []
@@ -201,7 +205,7 @@
self._names = []
self._name_map = {}
self._weave_name = weave_name
-
+ self._inclusion_cache = {}
def __eq__(self, other):
if not isinstance(other, Weave):
@@ -300,7 +304,6 @@
self._weave.append(('{', new_version))
self._weave.extend(text)
self._weave.append(('}', None))
-
return new_version
if len(parents) == 1:
@@ -308,10 +311,9 @@
if sha1 == self._sha1s[pv]:
# special case: same as the single parent
return new_version
-
ancestors = self.inclusions(parents)
-
+ self._inclusion_cache[(new_version,)] = ancestors | set([new_version])
l = self._weave
# basis a list of (origin, lineno, line)
@@ -379,17 +381,19 @@
def inclusions(self, versions):
"""Return set of all ancestors of given version(s)."""
+ tv = tuple(sorted(versions))
+ cached_val = self._inclusion_cache.get(tv)
+ if cached_val is not None:
+ return cached_val
i = set(versions)
- v = max(versions)
- try:
- while v >= 0:
- if v in i:
- # include all its parents
- i.update(self._parents[v])
- v -= 1
- return i
- except IndexError:
- raise ValueError("version %d not present in weave" % v)
+ for v in xrange(max(versions), 0, -1):
+ if v in i:
+ # include all its parents
+ i.update(self._parents[v])
+ self._inclusion_cache[tv] = i
+ return i
+ ## except IndexError:
+ ## raise ValueError("version %d not present in weave" % v)
def parents(self, version):
|