[PATCH 2 of 4] Do not use str.startswith or str.endswith to find a single character
Benoit Boissinot
benoit.boissinot at ens-lyon.org
Sun Aug 23 07:45:48 CDT 2009
On Sat, Aug 22, 2009 at 08:39:43PM +0200, Nicolas Dumazet wrote:
> # HG changeset patch
> # User Nicolas Dumazet <nicdumz.commits at gmail.com>
> # Date 1250960622 -7200
> # Node ID 51f0751ed3681aee75842e2351445ff30054062b
> # Parent f7a1dd3fa57b6be41c0c5535a16531b710571bb7
> Do not use str.startswith or str.endswith to find a single character
>
> When startswith (resp. endswith) is called on a single character, it is two times
> faster to directly compare that single character with str[0] (resp. str[-1]).
>
> * str.startswith(char) -> (str and) str[0] == char
> * str.endswith(char) -> (str and) str[-1] == char
I don't really like this one, I think it hurts the readability. Did you
check the python source to understand the issue (and does your benchmark
include the time to test if the string is not empty?) ?
regards,
Benoit
--
:wq
More information about the Mercurial-devel
mailing list