[New-bugs-announce] [issue17559] str.is* implementation seem suboptimal for single character strings
Gaëtan de Menten
report at bugs.python.org
Wed Mar 27 15:41:09 CET 2013
New submission from Gaëtan de Menten:
In isspace, isalpha, isalnum and isdigit, I see code like:
/* Shortcut for single character strings */
if (PyString_GET_SIZE(self) == 1 &&
isspace(*p))
return PyBool_FromLong(1);
Is it intentional to not use:
if (PyString_GET_SIZE(self) == 1))
return PyBool_FromLong(isspace(*p) != 0);
which would be faster when the result is False (but a tad slower when it is True because of the extra comparison).
Also, is there a reason (other than historical) why the macros Py_RETURN_TRUE and Py_RETURN_FALSE are not used instead of their equivalent functions PyBool_FromLong(1) and PyBool_FromLong(0)?
See:
http://hg.python.org/cpython/file/e87364449954/Objects/stringobject.c#l3324
----------
components: Interpreter Core
messages: 185338
nosy: gdementen
priority: normal
severity: normal
status: open
title: str.is* implementation seem suboptimal for single character strings
type: performance
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17559>
_______________________________________
More information about the New-bugs-announce
mailing list