Skip to content

Commit 8078e0e

Browse files
author
Jonathan Corbet
committed
docs: kdoc: micro-optimize KernRe
Rework _add_regex() to avoid doing the lookup twice for the (hopefully common) cache-hit case. Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Tested-by: Akira Yokosawa <akiyks@gmail.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/20250703184403.274408-3-corbet@lwn.net
1 parent e7e5403 commit 8078e0e

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

scripts/lib/kdoc/kdoc_re.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ def _add_regex(self, string, flags):
2929
"""
3030
Adds a new regex or re-use it from the cache.
3131
"""
32-
33-
if string in re_cache:
34-
self.regex = re_cache[string]
35-
else:
32+
self.regex = re_cache.get(string, None)
33+
if not self.regex:
3634
self.regex = re.compile(string, flags=flags)
37-
3835
if self.cache:
3936
re_cache[string] = self.regex
4037

0 commit comments

Comments
 (0)