]> www.infradead.org Git - users/willy/linux.git/commitdiff
docs: kdoc: micro-optimize KernRe
authorJonathan Corbet <corbet@lwn.net>
Mon, 30 Jun 2025 15:33:23 +0000 (09:33 -0600)
committerJonathan Corbet <corbet@lwn.net>
Mon, 30 Jun 2025 15:56:01 +0000 (09:56 -0600)
Switch KernRe::add_regex() to a try..except block to avoid looking up each
regex twice.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
scripts/lib/kdoc/kdoc_re.py

index e81695b273bfc2aa026c1128ab28c02290ffed4e..a467cd2f160b09628952372aa1c8d2a6a5353bb4 100644 (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