docs: kdoc: micro-optimize KernRe

Switch KernRe::add_regex() to a try..except block to avoid looking up each
regex twice.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
Jonathan Corbet
2025-06-30 09:33:23 -06:00
parent 362ec251a6
commit 09b9297478

View File

@@ -29,12 +29,10 @@ class KernRe:
"""
Adds a new regex or re-use it from the cache.
"""
if string in re_cache:
try:
self.regex = re_cache[string]
else:
except KeyError:
self.regex = re.compile(string, flags=flags)
if self.cache:
re_cache[string] = self.regex