summaryrefslogtreecommitdiffstats
path: root/Lib/plat-riscos
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 /Lib/plat-riscos
parentb370059233f0833dc2768422aee93a728eebbf26 (diff)
downloadcpython-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.zip
cpython-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.tar.gz
cpython-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.tar.bz2
patch [ 1105730 ] Faster commonprefix in macpath, ntpath, etc.
Diffstat (limited to 'Lib/plat-riscos')
-rw-r--r--Lib/plat-riscos/riscospath.py27
1 files changed, 10 insertions, 17 deletions
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?