[PATCH 2 of 3] convert/mtn: use mtn "automate stdio" when available

Patrick Mézard pmezard at gmail.com
Thu Mar 24 04:09:23 CDT 2011


Le 24/03/11 10:03, Patrick Mézard a écrit :
> Le 24/03/11 09:41, Martin Geisler a écrit :
>> Patrick Mézard <pmezard at gmail.com> writes:
>>
>>> Le 23/03/11 20:24, daniel.atallah at gmail.com a écrit :
>>>
>>>> +            commandnbr += read
>>>
>>> Concatenating strings character by character is usually not a good
>>> idea performance-wise in python. It could be better to use a StringIO.
>>> That said you can let this for now, the use of a command server
>>> already makes thing much much faster.
>>
>> CPython will do an in-place concatenation since Python 2.4, this is
>> mentioned right above this section:
>>
>>   http://docs.python.org/library/stdtypes.html?highlight=quadratic#string-methods
> 
> Interesting, I wasn't aware of this.
> 
> Another reason to keep the code as it is for now.
> 
>> However, as they also note, this is not to be depended on if you want
>> the same performance from other Python implementations. So if we're
>> talking about many strings, then I would use the normal idiom of
>> collecting them in a list first and then joining them at the end.
> 
> Since it is used to get converted file bytes, I wouldn't do this. Either keep the current version or use the Python moral equivalement of StringBuilder, like cStringIO or whatever it is today.

Hmm, no it is not. Please disregard all my remarks on this special point.

--
Patrick Mézard


More information about the Mercurial-devel mailing list