-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add PyUnicode_Equal()
function
#43
Comments
API shape seems fine, I prefer I find the performance argument fairly compelling, since ordering requires a lot of calculation (and realistically requires a number of options, including locale, to be correct). Having a fast equals method is likely to prevent people from relying on interning strings and comparing pointers. However, if the motivation really is that Knowing whether the people using the private function were looking specifically for speed or just using the first function their IDE told them about would help us make an informed decision here. I don't like when the proposal doesn't actually solve the problem given as the motivation (but am happy to change the motivation in this case). |
Also, we need to rule out |
Not that my opinion matters much here, but I might as well share my thoughts: I think a faster comparison protocol is a great idea (and one I'd be happy to help work on), but probably better suited for Though, maybe it's going a bit far to add this to the stable ABI -- the main beneficiaries from this are people who weren't using the limited API anyway, so really we're just adding another function to do the same thing, but with less version compatibility than |
Both projects use it for handling keyword arguments. I expected either that or attribute names (e.g. implementing descriptor-like behaviour in I think locale-aware comparisons have no place in the +1 for |
As naming,
I ran a benchmark on strings of 10 characters:
It returns |
I propose to add a public
PyUnicode_Equal(a, b)
function to the limited C API 3.14 to replace the private_PyUnicode_EQ()
function:API:
int PyUnicode_Equal(PyObject *a, PyObject *b)
1
if a is equal to b.0
if a is not equal to b.TypeError
exception and return-1
if a or b is not a Pythonstr
object.Python 3.13 moved the private
_PyUnicode_EQ()
function to internal C API. mypy and Pyodide are using it.The existing
PyUnicode_Compare()
isn't enough and has an issue.PyUnicode_Compare()
returns-1
for "less than" but also for the error case. The caller must callPyErr_Occurred()
which is inefficient. It causes an ambiguous return value: capi-workgroup/problems#1PyUnicode_Equal()
has no such ambiguous return value (-1
only means error). Moreover,PyUnicode_Equal()
may be a little bit faster thanPyUnicode_Compare()
, but I'm not sure about that.Vote to add this API:
The text was updated successfully, but these errors were encountered: