Patchwork keyword: replace map() with list comprehension

login
register
mail settings
Submitter Christian Ebert
Date Jan. 20, 2018, 11 a.m.
Message ID <f1d6d72008e373c24b80.1516446000@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa>
Download mbox | patch
Permalink /patch/27003/
State New
Headers show

Comments

Christian Ebert - Jan. 20, 2018, 11 a.m.
# HG changeset patch
# User Christian Ebert <blacktrash@gmx.net>
# Date 1516442383 -3600
#      Sat Jan 20 10:59:43 2018 +0100
# Node ID f1d6d72008e373c24b8057bebe999544f7a45711
# Parent  2384523cee4dcc83f67b73bf1862c68ddf1afc49
keyword: replace map() with list comprehension
Yuya Nishihara - Jan. 20, 2018, 12:29 p.m.
On Sat, 20 Jan 2018 12:00:00 +0100, Christian Ebert wrote:
> # HG changeset patch
> # User Christian Ebert <blacktrash@gmx.net>
> # Date 1516442383 -3600
> #      Sat Jan 20 10:59:43 2018 +0100
> # Node ID f1d6d72008e373c24b8057bebe999544f7a45711
> # Parent  2384523cee4dcc83f67b73bf1862c68ddf1afc49
> keyword: replace map() with list comprehension

for what?

Anyway, we're in code freeze. Please resend on February 1st.

> diff --git a/hgext/keyword.py b/hgext/keyword.py
> --- a/hgext/keyword.py
> +++ b/hgext/keyword.py
> @@ -238,7 +238,7 @@ class kwtemplater(object):
>      @util.propertycache
>      def escape(self):
>          '''Returns bar-separated and escaped keywords.'''
> -        return '|'.join(map(re.escape, self.templates.keys()))
> +        return '|'.join([re.escape(k) for k in self.templates.keys()])

Nit: [] isn't needed.
Christian Ebert - Jan. 20, 2018, 1:46 p.m.
* Yuya Nishihara on Saturday, January 20, 2018 at 21:29:37 +0900
> On Sat, 20 Jan 2018 12:00:00 +0100, Christian Ebert wrote:
>> # HG changeset patch
>> # User Christian Ebert <blacktrash@gmx.net>
>> # Date 1516442383 -3600
>> #      Sat Jan 20 10:59:43 2018 +0100
>> # Node ID f1d6d72008e373c24b8057bebe999544f7a45711
>> # Parent  2384523cee4dcc83f67b73bf1862c68ddf1afc49
>> keyword: replace map() with list comprehension
> 
> for what?

I was under the impression that this is (considered) faster?

> Anyway, we're in code freeze. Please resend on February 1st.

Sorry.

>> diff --git a/hgext/keyword.py b/hgext/keyword.py
>> --- a/hgext/keyword.py
>> +++ b/hgext/keyword.py
>> @@ -238,7 +238,7 @@ class kwtemplater(object):
>>     @util.propertycache
>>     def escape(self):
>>         '''Returns bar-separated and escaped keywords.'''
>> -        return '|'.join(map(re.escape, self.templates.keys()))
>> +        return '|'.join([re.escape(k) for k in self.templates.keys()])
> 
> Nit: [] isn't needed.

Thanks.
Yuya Nishihara - Jan. 21, 2018, 2:46 a.m.
On Sat, 20 Jan 2018 14:46:49 +0100, Christian Ebert wrote:
> * Yuya Nishihara on Saturday, January 20, 2018 at 21:29:37 +0900
> > On Sat, 20 Jan 2018 12:00:00 +0100, Christian Ebert wrote:
> >> # HG changeset patch
> >> # User Christian Ebert <blacktrash@gmx.net>
> >> # Date 1516442383 -3600
> >> #      Sat Jan 20 10:59:43 2018 +0100
> >> # Node ID f1d6d72008e373c24b8057bebe999544f7a45711
> >> # Parent  2384523cee4dcc83f67b73bf1862c68ddf1afc49
> >> keyword: replace map() with list comprehension
> > 
> > for what?
> 
> I was under the impression that this is (considered) faster?

Their performance characteristics wouldn't differ. It's rather a cosmetic issue
whether to use map() or not. Personally I like map() when it can get rid of
a parameter.
Christian Ebert - Jan. 21, 2018, 10:27 a.m.
* Yuya Nishihara on Sunday, January 21, 2018 at 11:46:12 +0900
> On Sat, 20 Jan 2018 14:46:49 +0100, Christian Ebert wrote:
>> * Yuya Nishihara on Saturday, January 20, 2018 at 21:29:37 +0900
>>> On Sat, 20 Jan 2018 12:00:00 +0100, Christian Ebert wrote:
>>>> keyword: replace map() with list comprehension
>>> 
>>> for what?
>> 
>> I was under the impression that this is (considered) faster?
> 
> Their performance characteristics wouldn't differ. It's rather a cosmetic issue
> whether to use map() or not. Personally I like map() when it can get rid of
> a parameter.

Me too, actually. Let's leave it at that then. Thanks for the 
feedback.

Patch

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -238,7 +238,7 @@  class kwtemplater(object):
     @util.propertycache
     def escape(self):
         '''Returns bar-separated and escaped keywords.'''
-        return '|'.join(map(re.escape, self.templates.keys()))
+        return '|'.join([re.escape(k) for k in self.templates.keys()])
 
     @util.propertycache
     def rekw(self):