New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
str.is* implementation seem suboptimal for single character strings #61759
Comments
In isspace, isalpha, isalnum and isdigit, I see code like: /* Shortcut for single character strings */ Is it intentional to not use: if (PyString_GET_SIZE(self) == 1)) 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: |
The shortcut seems fairly pointless to me. |
If you would like to improve Python, you have to focus on the development version which is Python 3.4. In this version, the code is different: if (length == 1)
return PyBool_FromLong(
Py_UNICODE_ISSPACE(PyUnicode_READ(kind, data, 0))); I'm not sure that having a special case for string of 1 character provide any speed up... |
There's still stuff in bytes_methods.c which looks like the old string code. |
Argl. I know I should have used 3.4... but that is what I thought I did. |
Benjamin, if that comment means there's still something to be done, please reopen. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: