]> www.infradead.org Git - users/willy/linux.git/commitdiff
docs: kdoc: micro-optimize KernRe
authorJonathan Corbet <corbet@lwn.net>
Thu, 3 Jul 2025 18:43:58 +0000 (12:43 -0600)
committerJonathan Corbet <corbet@lwn.net>
Tue, 8 Jul 2025 14:06:25 +0000 (08:06 -0600)
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
scripts/lib/kdoc/kdoc_re.py

index e81695b273bfc2aa026c1128ab28c02290ffed4e..612223e1e7238e654de1a6dd77e16b68947b0cc0 100644 (file)
@@ -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