[PATCH 3/3] Do not create lambda over and over in a cycle

Anne Mulhern amulhern at redhat.com
Thu Jan 22 14:40:36 UTC 2015





----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, January 21, 2015 5:50:36 AM
> Subject: [PATCH 3/3] Do not create lambda over and over in a cycle
> 
> Let's just define and create it once and use it over and over.
> 
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
>  scripts/makebumpver | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/makebumpver b/scripts/makebumpver
> index 57f549f..07ce065 100755
> --- a/scripts/makebumpver
> +++ b/scripts/makebumpver
> @@ -240,8 +240,9 @@ class MakeBumpVer:
>                         proc[0].strip('\n').split('\n'))
>  
>          if self.ignore and self.ignore != '':
> +            startswith_commit = lambda x: not x.startswith(commit)
>              for commit in self.ignore.split(','):
> -                lines = filter(lambda x: not x.startswith(commit), lines)
> +                lines = filter(startswith_commit, lines)
>  
>          rpm_log = []
>          bad_bump = False
> --
> 2.1.0
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

List comprehension would be that much prettier.

lines = [l for l in lines if not x.startswith(commit)]

or even,

commits = self.ignore.split(',')
lines = [l for l in lines if not any(l.startswith(c) for c in commits)]

which has advantage of not recomputing new list for every element in commit.

- mulhern


More information about the anaconda-patches mailing list