diff options
| author | Georg Brandl <georg@python.org> | 2005-08-03 07:30:12 +0000 | 
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2005-08-03 07:30:12 +0000 | 
| commit | 649f8e7de2ad8fc42748b56e8e64574478d2d7fe (patch) | |
| tree | 740d59f0b6fa4754093eb7c2f4165688c4f68642 /Lib/os2emxpath.py | |
| parent | b370059233f0833dc2768422aee93a728eebbf26 (diff) | |
| download | cpython-git-649f8e7de2ad8fc42748b56e8e64574478d2d7fe.tar.gz | |
patch [ 1105730 ] Faster commonprefix in macpath, ntpath, etc.
Diffstat (limited to 'Lib/os2emxpath.py')
| -rw-r--r-- | Lib/os2emxpath.py | 15 | 
1 files changed, 7 insertions, 8 deletions
| diff --git a/Lib/os2emxpath.py b/Lib/os2emxpath.py index 4c64324e9d..5b1cb186e3 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. | 
