mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-07 10:29:52 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user