gh-122288: Improve performances of fnmatch.translate (#122289)

Improve performance of this function by a factor of 1.7x.

Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
Bénédikt Tran 2024-11-27 17:42:45 +01:00 committed by GitHub
parent 14a05a8f43
commit 78cb377c62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 112 additions and 47 deletions

View file

@ -312,7 +312,7 @@ def translate(pat, *, recursive=False, include_hidden=False, seps=None):
if part:
if not include_hidden and part[0] in '*?':
results.append(r'(?!\.)')
results.extend(fnmatch._translate(part, f'{not_sep}*', not_sep))
results.extend(fnmatch._translate(part, f'{not_sep}*', not_sep)[0])
if idx < last_part_idx:
results.append(any_sep)
res = ''.join(results)