Skip to content

Commit 2a8e6a4

Browse files
committed
minor changes
1 parent 8fb5f47 commit 2a8e6a4

File tree

1 file changed

+31
-53
lines changed

1 file changed

+31
-53
lines changed

Lib/difflib.py

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def _build(self, start2, stop2):
142142
Current approach maintains reasonable memory guarantees
143143
and is also much simpler in comparison.
144144
"""
145-
if self.root is not None and self.cache == (start2, stop2):
145+
key = (start2, stop2)
146+
if self.root is not None and self.cache == key:
146147
return
147148

148149
self.root = root = [0, None, {}, -1]
@@ -186,7 +187,7 @@ def _build(self, start2, stop2):
186187

187188
last = curr
188189

189-
self.cache = (start2, stop2)
190+
self.cache = key
190191

191192
def find(self, seq1, start1=0, stop1=None, start2=0, stop2=None):
192193
size1 = len(seq1)
@@ -607,57 +608,34 @@ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
607608
calc = automaton
608609
besti, bestj, bestsize = calc.find(a, tmp_alo, tmp_ahi, blo, bhi)
609610

610-
# NOTE: Doing it at the same time results in bigger matches!
611-
# # If bjunk or bpopular were omitted in matching (performance reasons)
612-
# # We now extend the match to capture as much as we can
613-
# if self.bjunk or self.bpopular:
614-
# while besti > alo and bestj > blo and a[besti-1] == b[bestj-1]:
615-
# besti -= 1
616-
# bestj -= 1
617-
# bestsize += 1
618-
# lasti = besti + bestsize
619-
# lastj = bestj + bestsize
620-
# while lasti < ahi and lastj < bhi and a[lasti] == b[lastj]:
621-
# lasti += 1
622-
# lastj += 1
623-
# bestsize += 1
624-
625-
if self.bpopular:
626-
# Extend the best by non-junk elements on each end. In particular,
627-
# "popular" non-junk elements aren't in b2j, which greatly speeds
628-
# the inner loop above, but also means "the best" match so far
629-
# doesn't contain any junk *or* popular non-junk elements.
630-
while besti > alo and bestj > blo and \
631-
not isbjunk(b[bestj-1]) and \
632-
a[besti-1] == b[bestj-1]:
633-
besti -= 1
634-
bestj -= 1
635-
bestsize += 1
636-
637-
while besti+bestsize < ahi and bestj+bestsize < bhi and \
638-
not isbjunk(b[bestj+bestsize]) and \
639-
a[besti+bestsize] == b[bestj+bestsize]:
640-
bestsize += 1
641-
642-
if self.bjunk:
643-
# Now that we have a wholly interesting match (albeit possibly
644-
# empty!), we may as well suck up the matching junk on each
645-
# side of it too. Can't think of a good reason not to, and it
646-
# saves post-processing the (possibly considerable) expense of
647-
# figuring out what to do with it. In the case of an empty
648-
# interesting match, this is clearly the right thing to do,
649-
# because no other kind of match is possible in the regions.
650-
while besti > alo and bestj > blo and \
651-
isbjunk(b[bestj-1]) and \
652-
a[besti-1] == b[bestj-1]:
653-
besti -= 1
654-
bestj -= 1
655-
bestsize += 1
656-
657-
while besti+bestsize < ahi and bestj+bestsize < bhi and \
658-
isbjunk(b[bestj+bestsize]) and \
659-
a[besti+bestsize] == b[bestj+bestsize]:
660-
bestsize = bestsize + 1
611+
# Extend the best by non-junk elements on each end. In particular,
612+
# "popular" non-junk elements aren't in b2j, which greatly speeds
613+
# the inner loop above, but also means "the best" match so far
614+
# doesn't contain any junk *or* popular non-junk elements.
615+
while besti > alo and bestj > blo and \
616+
not isbjunk(b[bestj-1]) and \
617+
a[besti-1] == b[bestj-1]:
618+
besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
619+
while besti+bestsize < ahi and bestj+bestsize < bhi and \
620+
not isbjunk(b[bestj+bestsize]) and \
621+
a[besti+bestsize] == b[bestj+bestsize]:
622+
bestsize += 1
623+
624+
# Now that we have a wholly interesting match (albeit possibly
625+
# empty!), we may as well suck up the matching junk on each
626+
# side of it too. Can't think of a good reason not to, and it
627+
# saves post-processing the (possibly considerable) expense of
628+
# figuring out what to do with it. In the case of an empty
629+
# interesting match, this is clearly the right thing to do,
630+
# because no other kind of match is possible in the regions.
631+
while besti > alo and bestj > blo and \
632+
isbjunk(b[bestj-1]) and \
633+
a[besti-1] == b[bestj-1]:
634+
besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
635+
while besti+bestsize < ahi and bestj+bestsize < bhi and \
636+
isbjunk(b[bestj+bestsize]) and \
637+
a[besti+bestsize] == b[bestj+bestsize]:
638+
bestsize = bestsize + 1
661639

662640
return Match(besti, bestj, bestsize)
663641

0 commit comments

Comments
 (0)