diff mbox series

[XEN,v4,3/3] build: compat-xlat-header.py: optimisation to search for just '{' instead of [{}]

Message ID 20230119152256.15832-4-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show
Series xen: rework compat headers generation | expand

Commit Message

Anthony PERARD Jan. 19, 2023, 3:22 p.m. UTC
`fields` and `extrafields` always all the parts of a sub-struct, so
when there is '}', there is always a '{' before it. Also, both are
lists.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 xen/tools/compat-xlat-header.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Cooper Jan. 20, 2023, 6:26 p.m. UTC | #1
On 19/01/2023 3:22 pm, Anthony PERARD wrote:
> `fields` and `extrafields` always all the parts of a sub-struct, so
> when there is '}', there is always a '{' before it. Also, both are
> lists.
>
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  xen/tools/compat-xlat-header.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/xen/tools/compat-xlat-header.py b/xen/tools/compat-xlat-header.py
> index ae5c9f11c9..d0a864b68e 100644
> --- a/xen/tools/compat-xlat-header.py
> +++ b/xen/tools/compat-xlat-header.py
> @@ -105,7 +105,7 @@ def handle_field(prefix, name, id, type, fields):
>          else:
>              k = id.replace('.', '_')
>              print("%sXLAT_%s_HNDL_%s(_d_, _s_);" % (prefix, name, k), end='')
> -    elif not re_brackets.search(' '.join(fields)):
> +    elif not '{' in fields:
>          tag = ' '.join(fields)
>          tag = re.sub(r'\s*(struct|union)\s+(compat_)?(\w+)\s.*', '\\3', tag)
>          print(" \\")
> @@ -290,7 +290,7 @@ def build_body(name, tokens):
>      print(" \\\n} while (0)")
>  
>  def check_field(kind, name, field, extrafields):
> -    if not re_brackets.search(' '.join(extrafields)):
> +    if not '{' in extrafields:
>          print("; \\")
>          if len(extrafields) != 0:
>              for token in extrafields:

These are the only two users of re_brackets aren't they?  In which case
you should drop the re.compile() too.

~Andrew
Anthony PERARD Jan. 23, 2023, 10:30 a.m. UTC | #2
On Fri, Jan 20, 2023 at 06:26:14PM +0000, Andrew Cooper wrote:
> On 19/01/2023 3:22 pm, Anthony PERARD wrote:
> > `fields` and `extrafields` always all the parts of a sub-struct, so
> > when there is '}', there is always a '{' before it. Also, both are
> > lists.
> >
> > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> > ---
> >  xen/tools/compat-xlat-header.py | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/xen/tools/compat-xlat-header.py b/xen/tools/compat-xlat-header.py
> > index ae5c9f11c9..d0a864b68e 100644
> > --- a/xen/tools/compat-xlat-header.py
> > +++ b/xen/tools/compat-xlat-header.py
> > @@ -105,7 +105,7 @@ def handle_field(prefix, name, id, type, fields):
> >          else:
> >              k = id.replace('.', '_')
> >              print("%sXLAT_%s_HNDL_%s(_d_, _s_);" % (prefix, name, k), end='')
> > -    elif not re_brackets.search(' '.join(fields)):
> > +    elif not '{' in fields:
> >          tag = ' '.join(fields)
> >          tag = re.sub(r'\s*(struct|union)\s+(compat_)?(\w+)\s.*', '\\3', tag)
> >          print(" \\")
> > @@ -290,7 +290,7 @@ def build_body(name, tokens):
> >      print(" \\\n} while (0)")
> >  
> >  def check_field(kind, name, field, extrafields):
> > -    if not re_brackets.search(' '.join(extrafields)):
> > +    if not '{' in extrafields:
> >          print("; \\")
> >          if len(extrafields) != 0:
> >              for token in extrafields:
> 
> These are the only two users of re_brackets aren't they?  In which case
> you should drop the re.compile() too.

Indeed, I miss that, we can drop re_brackets.

Cheers,
Andrew Cooper Jan. 30, 2023, 3:10 p.m. UTC | #3
On 23/01/2023 10:30 am, Anthony PERARD wrote:
> On Fri, Jan 20, 2023 at 06:26:14PM +0000, Andrew Cooper wrote:
>> On 19/01/2023 3:22 pm, Anthony PERARD wrote:
>>> `fields` and `extrafields` always all the parts of a sub-struct, so
>>> when there is '}', there is always a '{' before it. Also, both are
>>> lists.
>>>
>>> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
>>> ---
>>>  xen/tools/compat-xlat-header.py | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/xen/tools/compat-xlat-header.py b/xen/tools/compat-xlat-header.py
>>> index ae5c9f11c9..d0a864b68e 100644
>>> --- a/xen/tools/compat-xlat-header.py
>>> +++ b/xen/tools/compat-xlat-header.py
>>> @@ -105,7 +105,7 @@ def handle_field(prefix, name, id, type, fields):
>>>          else:
>>>              k = id.replace('.', '_')
>>>              print("%sXLAT_%s_HNDL_%s(_d_, _s_);" % (prefix, name, k), end='')
>>> -    elif not re_brackets.search(' '.join(fields)):
>>> +    elif not '{' in fields:
>>>          tag = ' '.join(fields)
>>>          tag = re.sub(r'\s*(struct|union)\s+(compat_)?(\w+)\s.*', '\\3', tag)
>>>          print(" \\")
>>> @@ -290,7 +290,7 @@ def build_body(name, tokens):
>>>      print(" \\\n} while (0)")
>>>  
>>>  def check_field(kind, name, field, extrafields):
>>> -    if not re_brackets.search(' '.join(extrafields)):
>>> +    if not '{' in extrafields:
>>>          print("; \\")
>>>          if len(extrafields) != 0:
>>>              for token in extrafields:
>> These are the only two users of re_brackets aren't they?  In which case
>> you should drop the re.compile() too.
> Indeed, I miss that, we can drop re_brackets.

I've folded this deletion and queued the series for when OSSTest gets
unblocked.

~Andrew
diff mbox series

Patch

diff --git a/xen/tools/compat-xlat-header.py b/xen/tools/compat-xlat-header.py
index ae5c9f11c9..d0a864b68e 100644
--- a/xen/tools/compat-xlat-header.py
+++ b/xen/tools/compat-xlat-header.py
@@ -105,7 +105,7 @@  def handle_field(prefix, name, id, type, fields):
         else:
             k = id.replace('.', '_')
             print("%sXLAT_%s_HNDL_%s(_d_, _s_);" % (prefix, name, k), end='')
-    elif not re_brackets.search(' '.join(fields)):
+    elif not '{' in fields:
         tag = ' '.join(fields)
         tag = re.sub(r'\s*(struct|union)\s+(compat_)?(\w+)\s.*', '\\3', tag)
         print(" \\")
@@ -290,7 +290,7 @@  def build_body(name, tokens):
     print(" \\\n} while (0)")
 
 def check_field(kind, name, field, extrafields):
-    if not re_brackets.search(' '.join(extrafields)):
+    if not '{' in extrafields:
         print("; \\")
         if len(extrafields) != 0:
             for token in extrafields: