[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250704003251.1858ce60@foz.lan>
Date: Fri, 4 Jul 2025 00:32:50 +0200
From: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
To: Jonathan Corbet <corbet@....net>
Cc: linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org, Akira Yokosawa
<akiyks@...il.com>
Subject: Re: [PATCH v2 2/7] docs: kdoc: micro-optimize KernRe
Em Fri, 4 Jul 2025 00:31:46 +0200
Mauro Carvalho Chehab <mchehab+huawei@...nel.org> escreveu:
> Em Thu, 3 Jul 2025 12:43:58 -0600
> Jonathan Corbet <corbet@....net> escreveu:
>
> > Rework _add_regex() to avoid doing the lookup twice for the (hopefully
> > common) cache-hit case.
> >
> > Signed-off-by: Jonathan Corbet <corbet@....net>
> > ---
> > scripts/lib/kdoc/kdoc_re.py | 7 ++-----
> > 1 file changed, 2 insertions(+), 5 deletions(-)
> >
> > diff --git a/scripts/lib/kdoc/kdoc_re.py b/scripts/lib/kdoc/kdoc_re.py
> > index e81695b273bf..612223e1e723 100644
> > --- a/scripts/lib/kdoc/kdoc_re.py
> > +++ b/scripts/lib/kdoc/kdoc_re.py
> > @@ -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)
>
> With get, None is default...
>
> > + if not self.regex:
> > self.regex = re.compile(string, flags=flags)
>
> ... yet, as you're using get, better to code it as:
>
> self.regex = re_cache.get(string, re.compile(string, flags=flags))
For got to mention: with or without that:
Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@...nel.org>
>
> > -
> > if self.cache:
> > re_cache[string] = self.regex
> >
>
>
>
> Thanks,
> Mauro
Thanks,
Mauro
Powered by blists - more mailing lists