summaryrefslogtreecommitdiff
path: root/test/docutils_difflib.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/docutils_difflib.py')
-rw-r--r--test/docutils_difflib.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/test/docutils_difflib.py b/test/docutils_difflib.py
index 1865c2117..a41d4d5ba 100644
--- a/test/docutils_difflib.py
+++ b/test/docutils_difflib.py
@@ -163,6 +163,8 @@ class SequenceMatcher:
# b2j
# for x in b, b2j[x] is a list of the indices (into b)
# at which x appears; junk elements do not appear
+ # b2jhas
+ # b2j.has_key
# fullbcount
# for x in b, fullbcount[x] == the number of times x
# appears in b; only materialized if really needed (used
@@ -186,7 +188,7 @@ class SequenceMatcher:
# DON'T USE! Only __chain_b uses this. Use isbjunk.
# isbjunk
# for x in b, isbjunk(x) == isjunk(x) but much faster;
- # it's really the in operator of a hidden dict.
+ # it's really the has_key method of a hidden dict.
# DOES NOT WORK for x in a!
self.isjunk = isjunk
@@ -283,9 +285,10 @@ class SequenceMatcher:
# from the start.
b = self.b
self.b2j = b2j = {}
+ self.b2jhas = b2jhas = b2j.has_key
for i in xrange(len(b)):
elt = b[i]
- if elt in b2j:
+ if b2jhas(elt):
b2j[elt].append(i)
else:
b2j[elt] = [i]
@@ -301,12 +304,12 @@ class SequenceMatcher:
junkdict[elt] = 1 # value irrelevant; it's a set
del b2j[elt]
- # Now for x in b, isjunk(x) == x in junkdict, but the
+ # Now for x in b, isjunk(x) == junkdict.has_key(x), but the
# latter is much faster. Note too that while there may be a
# lot of junk in the sequence, the number of *unique* junk
# elements is probably small. So the memory burden of keeping
# this dict alive is likely trivial compared to the size of b2j.
- self.isbjunk = lambda elt: elt in junkdict
+ self.isbjunk = junkdict.has_key
def find_longest_match(self, alo, ahi, blo, bhi):
"""Find longest matching block in a[alo:ahi] and b[blo:bhi].
@@ -547,9 +550,9 @@ class SequenceMatcher:
# avail[x] is the number of times x appears in 'b' less the
# number of times we've seen it in 'a' so far ... kinda
avail = {}
- matches = 0
+ availhas, matches = avail.has_key, 0
for elt in self.a:
- if elt in avail:
+ if availhas(elt):
numb = avail[elt]
else:
numb = fullbcount.get(elt, 0)