[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <IA3PR11MB89867B010E36B682F10C1F44E59EA@IA3PR11MB8986.namprd11.prod.outlook.com>
Date: Thu, 29 Jan 2026 10:31:46 +0000
From: "Loktionov, Aleksandr" <aleksandr.loktionov@...el.com>
To: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>, Jonathan Corbet
<corbet@....net>, Linux Doc Mailing List <linux-doc@...r.kernel.org>
CC: "bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"intel-wired-lan@...ts.osuosl.org" <intel-wired-lan@...ts.osuosl.org>,
"linux-hardening@...r.kernel.org" <linux-hardening@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>, Mauro Carvalho Chehab
<mchehab@...nel.org>, Randy Dunlap <rdunlap@...radead.org>
Subject: RE: [Intel-wired-lan] [PATCH v3 17/30] docs: kdoc_re: don't recompile
NextMatch regex every time
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@...osl.org> On Behalf
> Of Mauro Carvalho Chehab
> Sent: Thursday, January 29, 2026 9:08 AM
> To: Jonathan Corbet <corbet@....net>; Linux Doc Mailing List <linux-
> doc@...r.kernel.org>
> Cc: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>;
> bpf@...r.kernel.org; intel-wired-lan@...ts.osuosl.org; linux-
> hardening@...r.kernel.org; linux-kernel@...r.kernel.org;
> netdev@...r.kernel.org; Mauro Carvalho Chehab <mchehab@...nel.org>;
> Randy Dunlap <rdunlap@...radead.org>
> Subject: [Intel-wired-lan] [PATCH v3 17/30] docs: kdoc_re: don't
> recompile NextMatch regex every time
>
> Store delimiters and its regex-compiled version as const vars.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
> ---
> tools/lib/python/kdoc/kdoc_re.py | 35 ++++++++++++++++++++-----------
> -
> 1 file changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/tools/lib/python/kdoc/kdoc_re.py
> b/tools/lib/python/kdoc/kdoc_re.py
> index 3f405addcc58..7b7ddc50ac36 100644
> --- a/tools/lib/python/kdoc/kdoc_re.py
> +++ b/tools/lib/python/kdoc/kdoc_re.py
> @@ -99,6 +99,13 @@ class KernRe:
> self.last_match = self.regex.search(string)
> return self.last_match
>
> + def finditer(self, string):
> + """
> + Alias to re.finditer.
> + """
> +
> + return self.regex.finditer(string)
> +
> def findall(self, string):
> """
> Alias to re.findall.
> @@ -134,6 +141,16 @@ class KernRe:
>
> return self.last_match.groups()
>
> +#: Nested delimited pairs (brackets and parenthesis) DELIMITER_PAIRS
> =
> +{
> + '{': '}',
> + '(': ')',
> + '[': ']',
> +}
> +
> +#: compiled delimiters
> +RE_DELIM = KernRe(r'[\{\}\[\]\(\)]')
> +
>
> class NestedMatch:
> """
> @@ -183,14 +200,6 @@ class NestedMatch:
> #
> # FOO(arg1, arg2, arg3)
>
> - DELIMITER_PAIRS = {
> - '{': '}',
> - '(': ')',
> - '[': ']',
> - }
> -
> - RE_DELIM = re.compile(r'[\{\}\[\]\(\)]')
> -
> def _search(self, regex, line):
> """
> Finds paired blocks for a regex that ends with a delimiter.
> @@ -220,13 +229,13 @@ class NestedMatch:
> escape = False
>
> d = line[offset - 1]
> - if d not in self.DELIMITER_PAIRS:
> + if d not in DELIMITER_PAIRS:
> continue
>
> - end = self.DELIMITER_PAIRS[d]
> + end = DELIMITER_PAIRS[d]
> stack.append(end)
>
> - for match in self.RE_DELIM.finditer(line[offset:]):
> + for match in RE_DELIM.finditer(line[offset:]):
> pos = match.start() + offset
>
> d = line[pos]
> @@ -247,8 +256,8 @@ class NestedMatch:
> string_char = d
> continue
>
> - if d in self.DELIMITER_PAIRS:
> - end = self.DELIMITER_PAIRS[d]
> + if d in DELIMITER_PAIRS:
> + end = DELIMITER_PAIRS[d]
>
> stack.append(end)
> continue
> --
> 2.52.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@...el.com>
Powered by blists - more mailing lists