]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42799: fnmatch module: bump up size of lru_cache for patterns (GH-27084)
authorandrei kulakov <andrei.avk@gmail.com>
Thu, 15 Jul 2021 10:53:26 +0000 (06:53 -0400)
committerGitHub <noreply@github.com>
Thu, 15 Jul 2021 10:53:26 +0000 (12:53 +0200)
Doc/library/fnmatch.rst
Lib/fnmatch.py
Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst [new file with mode: 0644]

index 925f08e914685e89c5c176a53ad39fc368d4d7db..9163da57c7b9994389fe410c1ed8d2bab87a01e2 100644 (file)
@@ -46,6 +46,9 @@ module.  See module :mod:`glob` for pathname expansion (:mod:`glob` uses
 a period are not special for this module, and are matched by the ``*`` and ``?``
 patterns.
 
+Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
+cache the compiled regex patterns in the following functions: :func:`fnmatch`,
+:func:`fnmatchcase`, :func:`filter`.
 
 .. function:: fnmatch(filename, pattern)
 
index 7c52c23067d40f3e808b160647ff3537823325ec..239c7490d49eec36dadd4b45e3295accc7b900b6 100644 (file)
@@ -41,7 +41,7 @@ def fnmatch(name, pat):
     pat = os.path.normcase(pat)
     return fnmatchcase(name, pat)
 
-@functools.lru_cache(maxsize=256, typed=True)
+@functools.lru_cache(maxsize=32768, typed=True)
 def _compile_pattern(pat):
     if isinstance(pat, bytes):
         pat_str = str(pat, 'ISO-8859-1')
diff --git a/Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst b/Misc/NEWS.d/next/Library/2021-07-10-19-55-13.bpo-42799.ad4tq8.rst
new file mode 100644 (file)
index 0000000..8a25800
--- /dev/null
@@ -0,0 +1,4 @@
+In :mod:`fnmatch`, the cache size for compiled regex patterns
+(:func:`functools.lru_cache`) was bumped up from 256 to 32768, affecting
+functions: :func:`fnmatch.fnmatch`, :func:`fnmatch.fnmatchcase`,
+:func:`fnmatch.filter`.