summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2005-08-03 07:30:12 (GMT)
committerGeorg Brandl <georg@python.org>2005-08-03 07:30:12 (GMT)
commit649f8e7de2ad8fc42748b56e8e64574478d2d7fe (patch)
tree740d59f0b6fa4754093eb7c2f4165688c4f68642
parentb370059233f0833dc2768422aee93a728eebbf26 (diff)
downloadcpython-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.zip
cpython-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.tar.gz
cpython-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.tar.bz2
patch [ 1105730 ] Faster commonprefix in macpath, ntpath, etc.
-rw-r--r--Lib/macpath.py16
-rw-r--r--Lib/ntpath.py15
-rw-r--r--Lib/os2emxpath.py15
-rw-r--r--Lib/plat-riscos/riscospath.py27
-rw-r--r--Misc/NEWS3
5 files changed, 35 insertions, 41 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py
index f50f660..dc7f753 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -175,14 +175,14 @@ def lexists(path):
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."""
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index 649e424..35f266c 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -212,14 +212,13 @@ def dirname(p):
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.
diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py
index 4c64324..5b1cb18 100644
--- a/Lib/os2emxpath.py
+++ b/Lib/os2emxpath.py
@@ -173,14 +173,13 @@ def dirname(p):
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.
diff --git a/Lib/plat-riscos/riscospath.py b/Lib/plat-riscos/riscospath.py
index 97b4f65..ea39e60 100644
--- a/Lib/plat-riscos/riscospath.py
+++ b/Lib/plat-riscos/riscospath.py
@@ -168,23 +168,16 @@ def dirname(p):
return split(p)[0]
-def commonprefix(ps):
- """
- Return the longest prefix of all list elements. Purely string-based; does not
- separate any path parts. Why am I in os.path?
- """
- if len(ps)==0:
- return ''
- prefix= ps[0]
- for p in ps[1:]:
- prefix= prefix[:len(p)]
- for i in range(len(prefix)):
- if prefix[i] <> p[i]:
- prefix= prefix[:i]
- if i==0:
- return ''
- break
- return prefix
+def commonprefix(m):
+ "Given a list of pathnames, returns the longest common leading component"
+ if not m: return ''
+ 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]
## File access functions. Why are we in os.path?
diff --git a/Misc/NEWS b/Misc/NEWS
index ebc9b0d..8a2d504 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -178,6 +178,9 @@ Extension Modules
Library
-------
+- Patch #1105730: Apply the new implementation of commonprefix in posixpath
+ to ntpath, macpath, os2emxpath and riscospath.
+
- Fix a problem in Tkinter introduced by SF patch #869468: delete bogus
__hasattr__ and __delattr__ methods on class Tk that were breaking
Tkdnd.