summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-04-02 01:18:30 (GMT)
committerGuido van Rossum <guido@python.org>1997-04-02 01:18:30 (GMT)
commit659a3b58817960e28daa60e9e09c09aaab3a83c6 (patch)
tree7f8064fcaac6b874bee14290f2a9a35a52e22eb0
parentc054d70aee8080dcbb81a0231fcd416811ffe830 (diff)
downloadcpython-659a3b58817960e28daa60e9e09c09aaab3a83c6.zip
cpython-659a3b58817960e28daa60e9e09c09aaab3a83c6.tar.gz
cpython-659a3b58817960e28daa60e9e09c09aaab3a83c6.tar.bz2
Optimized the hell out of listmessages().
Changed numericprog regexpr to make it faster to check. Removed now unnecessary checks for os.curdir, os.pardir.
-rw-r--r--Lib/mhlib.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/mhlib.py b/Lib/mhlib.py
index dd38762..990cd9a 100644
--- a/Lib/mhlib.py
+++ b/Lib/mhlib.py
@@ -140,7 +140,6 @@ class MH:
folders = []
path = self.getpath()
for name in os.listdir(path):
- if name in (os.curdir, os.pardir): continue
fullname = os.path.join(path, name)
if os.path.isdir(fullname):
folders.append(name)
@@ -160,7 +159,6 @@ class MH:
subfolders = []
subnames = os.listdir(fullname)
for subname in subnames:
- if subname in (os.curdir, os.pardir): continue
fullsubname = os.path.join(fullname, subname)
if os.path.isdir(fullsubname):
name_subname = os.path.join(name, subname)
@@ -189,7 +187,6 @@ class MH:
subfolders = []
subnames = os.listdir(fullname)
for subname in subnames:
- if subname in (os.curdir, os.pardir): continue
if subname[0] == ',' or isnumeric(subname): continue
fullsubname = os.path.join(fullname, subname)
if os.path.isdir(fullsubname):
@@ -227,7 +224,6 @@ class MH:
def deletefolder(self, name):
fullname = os.path.join(self.getpath(), name)
for subname in os.listdir(fullname):
- if subname in (os.curdir, os.pardir): continue
fullsubname = os.path.join(fullname, subname)
try:
os.unlink(fullsubname)
@@ -239,9 +235,9 @@ class MH:
# Class representing a particular folder
-numericprog = regex.compile('[1-9][0-9]*')
+numericprog = regex.compile('^[1-9][0-9]*$')
def isnumeric(str):
- return numericprog.match(str) == len(str)
+ return numericprog.match(str) >= 0
class Folder:
@@ -284,13 +280,15 @@ class Folder:
# As a side effect, set self.last to the last message (or 0)
def listmessages(self):
messages = []
+ match = numericprog.match
+ append = messages.append
for name in os.listdir(self.getfullname()):
- if name[0] != "," and \
- numericprog.match(name) == len(name):
- messages.append(string.atoi(name))
+ if match(name) >= 0:
+ append(name)
+ messages = map(string.atoi, messages)
messages.sort()
if messages:
- self.last = max(messages)
+ self.last = messages[-1]
else:
self.last = 0
return messages