[Python-checkins] python/dist/src/Lib macpath.py, 1.50, 1.51 ntpath.py, 1.61, 1.62 os2emxpath.py, 1.13, 1.14
birkenfeld@users.sourceforge.net
birkenfeld at users.sourceforge.net
Wed Aug 3 09:30:14 CEST 2005
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26243/Lib
Modified Files:
macpath.py ntpath.py os2emxpath.py
Log Message:
patch [ 1105730 ] Faster commonprefix in macpath, ntpath, etc.
Index: macpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/macpath.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- macpath.py 30 Aug 2004 13:39:50 -0000 1.50
+++ macpath.py 3 Aug 2005 07:30:11 -0000 1.51
@@ -175,14 +175,14 @@
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
- prefix = m[0]
- for item in m:
- for i in range(len(prefix)):
- if prefix[:i+1] != item[:i+1]:
- prefix = prefix[:i]
- if i == 0: return ''
- break
- return prefix
+ s1 = min(m)
+ s2 = max(m)
+ n = min(len(s1), len(s2))
+ for i in xrange(n):
+ if s1[i] != s2[i]:
+ return s1[:i]
+ return s1[:n]
+
def expandvars(path):
"""Dummy to retain interface-compatibility with other operating systems."""
Index: ntpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ntpath.py,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- ntpath.py 30 Aug 2004 10:19:55 -0000 1.61
+++ ntpath.py 3 Aug 2005 07:30:12 -0000 1.62
@@ -212,14 +212,13 @@
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
- prefix = m[0]
- for item in m:
- for i in range(len(prefix)):
- if prefix[:i+1] != item[:i+1]:
- prefix = prefix[:i]
- if i == 0: return ''
- break
- return prefix
+ s1 = min(m)
+ s2 = max(m)
+ n = min(len(s1), len(s2))
+ for i in xrange(n):
+ if s1[i] != s2[i]:
+ return s1[:i]
+ return s1[:n]
# Get size, mtime, atime of files.
Index: os2emxpath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os2emxpath.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- os2emxpath.py 30 Aug 2004 10:19:55 -0000 1.13
+++ os2emxpath.py 3 Aug 2005 07:30:12 -0000 1.14
@@ -173,14 +173,13 @@
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
- prefix = m[0]
- for item in m:
- for i in range(len(prefix)):
- if prefix[:i+1] != item[:i+1]:
- prefix = prefix[:i]
- if i == 0: return ''
- break
- return prefix
+ s1 = min(m)
+ s2 = max(m)
+ n = min(len(s1), len(s2))
+ for i in xrange(n):
+ if s1[i] != s2[i]:
+ return s1[:i]
+ return s1[:n]
# Get size, mtime, atime of files.
More information about the Python-checkins
mailing list