summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>1998-02-10 21:35:49 (GMT)
committerFred Drake <fdrake@acm.org>1998-02-10 21:35:49 (GMT)
commita94d21f44ec3a3a52a5ee4f81fcfaa7e282cd5f5 (patch)
tree79df7e18ede9c67b19a52243fa1d6601e61a3c51 /Doc
parent2e6c13f150a7f8f8d8e4b24076a8baf96601bfe2 (diff)
downloadcpython-a94d21f44ec3a3a52a5ee4f81fcfaa7e282cd5f5.zip
cpython-a94d21f44ec3a3a52a5ee4f81fcfaa7e282cd5f5.tar.gz
cpython-a94d21f44ec3a3a52a5ee4f81fcfaa7e282cd5f5.tar.bz2
Minor performance nits.
Diffstat (limited to 'Doc')
-rwxr-xr-xDoc/indfix.py34
-rwxr-xr-xDoc/tools/indfix.py34
2 files changed, 36 insertions, 32 deletions
diff --git a/Doc/indfix.py b/Doc/indfix.py
index 3435212..ede1d16 100755
--- a/Doc/indfix.py
+++ b/Doc/indfix.py
@@ -24,19 +24,20 @@ import StringIO
import sys
-def strcasecmp(e1, e2, lower=string.lower):
+def cmp_entries(e1, e2, lower=string.lower):
return cmp(lower(e1[1]), lower(e2[1])) or cmp(e1, e2)
-def dump_entries(ofp, entries):
+def dump_entries(write, entries):
if len(entries) == 1:
- ofp.write(" \\item %s (%s)%s\n" % entries[0])
+ write(" \\item %s (%s)%s\n" % entries[0])
return
- ofp.write(" \item %s\n" % entries[0][0])
+ write(" \item %s\n" % entries[0][0])
# now sort these in a case insensitive manner:
- entries.sort(strcasecmp)
+ if len(entries) > 0:
+ entries.sort(cmp_entries)
for xxx, subitem, pages in entries:
- ofp.write(" \subitem %s%s\n" % (subitem, pages))
+ write(" \subitem %s%s\n" % (subitem, pages))
breakable_re = re.compile(r" \\item (.*) [(](.*)[)]((?:, \d+)+)")
@@ -55,27 +56,28 @@ def main():
else:
fp = open(filename)
ofp = StringIO.StringIO()
- item, subitem = None, None
entries = []
+ match = breakable_re.match
+ write = ofp.write
while 1:
line = fp.readline()
if not line:
break
- m = breakable_re.match(line)
+ m = match(line)
if m:
entry = m.group(1, 2, 3)
- if entries:
- if entries[-1][0] != entry[0]:
- dump_entries(ofp, entries)
- entries = []
+ if entries and entries[-1][0] != entry[0]:
+ dump_entries(write, entries)
+ entries = []
entries.append(entry)
elif entries:
- dump_entries(ofp, entries)
+ dump_entries(write, entries)
entries = []
- ofp.write(line)
+ write(line)
else:
- pass
- ofp.write(line)
+ write(line)
+ del write
+ del match
fp.close()
if outfile == "-":
fp = sys.stdout
diff --git a/Doc/tools/indfix.py b/Doc/tools/indfix.py
index 3435212..ede1d16 100755
--- a/Doc/tools/indfix.py
+++ b/Doc/tools/indfix.py
@@ -24,19 +24,20 @@ import StringIO
import sys
-def strcasecmp(e1, e2, lower=string.lower):
+def cmp_entries(e1, e2, lower=string.lower):
return cmp(lower(e1[1]), lower(e2[1])) or cmp(e1, e2)
-def dump_entries(ofp, entries):
+def dump_entries(write, entries):
if len(entries) == 1:
- ofp.write(" \\item %s (%s)%s\n" % entries[0])
+ write(" \\item %s (%s)%s\n" % entries[0])
return
- ofp.write(" \item %s\n" % entries[0][0])
+ write(" \item %s\n" % entries[0][0])
# now sort these in a case insensitive manner:
- entries.sort(strcasecmp)
+ if len(entries) > 0:
+ entries.sort(cmp_entries)
for xxx, subitem, pages in entries:
- ofp.write(" \subitem %s%s\n" % (subitem, pages))
+ write(" \subitem %s%s\n" % (subitem, pages))
breakable_re = re.compile(r" \\item (.*) [(](.*)[)]((?:, \d+)+)")
@@ -55,27 +56,28 @@ def main():
else:
fp = open(filename)
ofp = StringIO.StringIO()
- item, subitem = None, None
entries = []
+ match = breakable_re.match
+ write = ofp.write
while 1:
line = fp.readline()
if not line:
break
- m = breakable_re.match(line)
+ m = match(line)
if m:
entry = m.group(1, 2, 3)
- if entries:
- if entries[-1][0] != entry[0]:
- dump_entries(ofp, entries)
- entries = []
+ if entries and entries[-1][0] != entry[0]:
+ dump_entries(write, entries)
+ entries = []
entries.append(entry)
elif entries:
- dump_entries(ofp, entries)
+ dump_entries(write, entries)
entries = []
- ofp.write(line)
+ write(line)
else:
- pass
- ofp.write(line)
+ write(line)
+ del write
+ del match
fp.close()
if outfile == "-":
fp = sys.stdout