[Cython] PATCH: removing strcmp() in favor of custom impl or other fixes

Robert Bradshaw robertwb at math.washington.edu
Sat Mar 7 21:22:54 CET 2009


On Mar 7, 2009, at 11:47 AM, Stefan Behnel wrote:

> Lisandro Dalcin wrote:
>> Here you have the patch... Implemented as an (inline) function in a
>> utility code
>
> Since it's never used for anything but string equality checks, it  
> would be
> better to restrict it to that (i.e. 1/0), instead of using the normal
> strcmp() -1,0,1 return values and additionally checking for "== 0"
> everywhere in the code. Maybe call it "__Pyx_StrEqual()".

+1

>> * The API import function uses a different thing, just a while  
>> loop. I
>> do not want to complicate things in generated API headers for
>> something that can be done with two auxiliar variables and a one-line
>> while loop.
>
> Sure, good idea.
>
>
>> * In the keyword handling code, I've used _PyString_Eq(), which is
>> available in the C-API for Py2. If Python's C-API provides what we
>> need, let's use it. Moreover, just in case, please see the
>> implementation of _PyString_Eq(), it is smarter (and likely faster)
>> than a strcmp() call ;-).
>
> Note that I already used (almost) the same optimisation in the  
> code, which
> now becomes superfluous. Although I expect it to be a lot faster to  
> check
> the length inside the loop before calling into the Python's C-API,  
> these
> checks should be rare enough to just make that
>
> 	if (_PyString_Eq(**name, key)) ...
>
> The real fast-path is the loop with plain string pointer equality  
> checks
> before all that. (BTW, note that this function is only available in  
> Py2, so
> it's perfectly ok to use it here but not in general).
>
> Stefan
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev



More information about the Cython-dev mailing list