diff options
author | Jonathan Corbet <corbet@lwn.net> | 2025-07-03 12:43:58 -0600 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2025-07-08 08:06:25 -0600 |
commit | 8078e0ed1f3f3bac776b412b0f85ada86f91fef0 (patch) | |
tree | f5bfc6121ba005e34a8fafc32cd00509a1c8d409 /scripts/lib/kdoc/kdoc_re.py | |
parent | e7e540363cc52207c5245ad934180db1a1f96522 (diff) |
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
Diffstat (limited to 'scripts/lib/kdoc/kdoc_re.py')
-rw-r--r-- | scripts/lib/kdoc/kdoc_re.py | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/scripts/lib/kdoc/kdoc_re.py b/scripts/lib/kdoc/kdoc_re.py index e81695b273bf..612223e1e723 100644 --- a/scripts/lib/kdoc/kdoc_re.py +++ b/scripts/lib/kdoc/kdoc_re.py @@ -29,12 +29,9 @@ class KernRe: """ Adds a new regex or re-use it from the cache. """ - - if string in re_cache: - self.regex = re_cache[string] - else: + self.regex = re_cache.get(string, None) + if not self.regex: self.regex = re.compile(string, flags=flags) - if self.cache: re_cache[string] = self.regex |