summaryrefslogtreecommitdiffstats
path: root/Lib/difflib.py
diff options
context:
space:
mode:
authorTerry Reedy <tjreedy@udel.edu>2010-12-15 20:18:10 (GMT)
committerTerry Reedy <tjreedy@udel.edu>2010-12-15 20:18:10 (GMT)
commit17a59252e8505439decbdf80c73d2465288f65c7 (patch)
treea013b989af70181e83f9dde3f40bc09293ea3b76 /Lib/difflib.py
parent50ba19ee454e47b44cb0a9f00746d8ecdf0aa1b2 (diff)
downloadcpython-17a59252e8505439decbdf80c73d2465288f65c7.zip
cpython-17a59252e8505439decbdf80c73d2465288f65c7.tar.gz
cpython-17a59252e8505439decbdf80c73d2465288f65c7.tar.bz2
Issue 10534, difflib: tweak doc; test new SequenceMatcher instance attributes; avoid unneeded lists of SM.b2j keys and items in .__chain_b. Do not backport.
Diffstat (limited to 'Lib/difflib.py')
-rw-r--r--Lib/difflib.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py
index a1c5ec0..381721a 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -320,20 +320,22 @@ class SequenceMatcher:
self.bjunk = junk = set()
isjunk = self.isjunk
if isjunk:
- for elt in list(b2j.keys()): # using list() since b2j is modified
+ for elt in b2j.keys():
if isjunk(elt):
junk.add(elt)
- del b2j[elt]
+ for elt in junk: # separate loop avoids separate list of keys
+ del b2j[elt]
# Purge popular elements that are not junk
self.bpopular = popular = set()
n = len(b)
if self.autojunk and n >= 200:
ntest = n // 100 + 1
- for elt, idxs in list(b2j.items()):
+ for elt, idxs in b2j.items():
if len(idxs) > ntest:
popular.add(elt)
- del b2j[elt]
+ for elt in popular: # ditto; as fast for 1% deletion
+ del b2j[elt]
def isbjunk(self, item):
"Deprecated; use 'item in SequenceMatcher().bjunk'."