mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
patch [ 1105730 ] Faster commonprefix in macpath, ntpath, etc.
This commit is contained in:
parent
b370059233
commit
649f8e7de2
5 changed files with 35 additions and 41 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue