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
Merge duplicated _Py_IDENTIFIER identifiers in C code #63713
Comments
Some C files use more than once the same _Py_IDENTIFIER identifier. It would be more efficient to merge duplicated identifiers. Just move the definition to the top of the file. _Py_IDENTIFIER(as_integer_ratio): Modules/_datetimemodule.c:1569 _Py_IDENTIFIER(cursor): Modules/_sqlite/connection.c:1282 _Py_IDENTIFIER(fromutc): Modules/_datetimemodule.c:4210 _Py_IDENTIFIER(len): Objects/typeobject.c:5071 _Py_IDENTIFIER(insert): Modules/_bisectmodule.c:198 _Py_IDENTIFIER(isoformat): Modules/_datetimemodule.c:2638 _Py_IDENTIFIER(strftime): Modules/_datetimemodule.c:1280 |
See also issue bpo-19515 which is more general. |
Oh, I forgot: _Py_IDENTIFIER(delitem): Objects/typeobject.c:5132 |
I'll provide a patch later tonight. |
I've merged the _Py_IDENTIFIER identifiers mentioned above. I stumbled over anohter instance where _Py_IDENTIFIER is used more than once: _Py_IDENTIFIER(setitem) : Objects/typeobject.c#l5133 |
As a matter of style, I suggest that all identifiers are moved to the top of a file if some of them live there. IOW, it's (IMO) unstylish to have some at the top, and some in the middle (although this works perfectly fine, of course). |
Another matter of style: I suggest alphabetical order for the identifiers, at least when the list gets long. |
The patch I promised above. |
I added a new patch with sorted _Py_IDENTIFIERs. Regarding all identifiers at the top, I guess it might be more stylish, but it might affect performance. I'm not sure, though. |
merge_py_identifiers_sorted.patch looks good to me. |
New changeset 4a09cc62419b by Martin v. Löwis in branch 'default': |
Thanks for the patch. Note: moving all identifiers would not have made a difference. They are static variables, so from a run-time point of view, there is no difference whether they are inside or outside of functions. |
New changeset cb4c964800af by Victor Stinner in branch 'default': |
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: