[Xcb] [PATCH libxcb 05/18] c_client.py: use comprehensions instead of map/filter

Christian Linhart chris at DemoRecorder.com
Sun Mar 15 02:43:40 PDT 2015


Hi again Ran,

Thank you for this patch, too.

It makes the code more readable and more pythonic.

Also, I have tested it and it does not change the generated code.

Therefore, after a long delay:
Reviewed-by: Christian Linhart <chris at demorecorder.com>

Chris

P.S.: I am going to push this patch now because it really had more than enough time for being reviewed or for raising objections.


On 10/12/14 20:58, Ran Benita wrote:
> Signed-off-by: Ran Benita <ran234 at gmail.com>
> ---
>  src/c_client.py | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/src/c_client.py b/src/c_client.py
> index 63bb7d6..fa37772 100644
> --- a/src/c_client.py
> +++ b/src/c_client.py
> @@ -544,7 +544,7 @@ def get_expr_fields(self):
>          prefix.append(('', '', self))
>  
>      all_fields = _c_helper_resolve_field_names (prefix)
> -    resolved_fields_names = list(filter(lambda x: x in all_fields.keys(), unresolved_fields_names))
> +    resolved_fields_names = [x for x in unresolved_fields_names if x in all_fields]
>      if len(unresolved_fields_names) != len(resolved_fields_names):
>          raise Exception("could not resolve all fields for %s" % self.name)
>  
> @@ -783,8 +783,8 @@ def _c_serialize_helper_list_field(context, self, field,
>      param_names = [p[2] for p in params]
>  
>      expr_fields_names = [f.field_name for f in get_expr_fields(field.type)]
> -    resolved = list(filter(lambda x: x in param_names, expr_fields_names))
> -    unresolved = list(filter(lambda x: x not in param_names, expr_fields_names))
> +    resolved = [x for x in expr_fields_names if x in param_names]
> +    unresolved = [x for x in expr_fields_names if x not in param_names]
>  
>      field_mapping = {}
>      for r in resolved:
> @@ -797,8 +797,8 @@ def _c_serialize_helper_list_field(context, self, field,
>                              field.c_field_name)
>  
>          field_mapping.update(_c_helper_resolve_field_names(prefix))
> -        resolved += list(filter(lambda x: x in field_mapping, unresolved))
> -        unresolved = list(filter(lambda x: x not in field_mapping, unresolved))
> +        resolved += [x for x in unresolved if x in field_mapping]
> +        unresolved = [x for x in unresolved if x not in field_mapping]
>          if len(unresolved)>0:
>              raise Exception('could not resolve the length fields required for list %s' % field.c_field_name)
>  
> @@ -1131,7 +1131,7 @@ def _c_serialize(context, self):
>          param_str.append("%s%s%s  %s%s  /**< */" % (indent, typespec, spacing, pointerspec, field_name))
>      # insert function name
>      param_str[0] = "%s (%s" % (func_name, param_str[0].strip())
> -    param_str = list(map(lambda x: "%s," % x, param_str))
> +    param_str = ["%s," % x for x in param_str]
>      for s in param_str[:-1]:
>          _hc(s)
>      _h("%s);" % param_str[-1].rstrip(','))
> @@ -1210,7 +1210,7 @@ def _c_serialize(context, self):
>          if not (self.is_switch or self.c_var_followed_by_fixed_fields):
>  
>              # look if we have to declare an '_aux' variable at all
> -            if len(list(filter(lambda x: x.find('_aux')!=-1, code_lines)))>0:
> +            if any('_aux' in x for x in code_lines):
>                  if not self.c_var_followed_by_fixed_fields:
>                      _c('    const %s *_aux = (%s *)_buffer;', self.c_type, self.c_type)
>                  else:



More information about the Xcb mailing list