Skip to content
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

Use _PyLong_GetOne() and _PyLong_GetZero() in Objects #125442

Closed
hikariyo opened this issue Oct 14, 2024 · 0 comments
Closed

Use _PyLong_GetOne() and _PyLong_GetZero() in Objects #125442

hikariyo opened this issue Oct 14, 2024 · 0 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@hikariyo
Copy link

hikariyo commented Oct 14, 2024

Feature or enhancement

Proposal:

There are several statements in longobject.c that still uses PyLong_FromLong(0L) and PyLong_FromLong(1L).

cpython/Objects/longobject.c

Lines 5006 to 5008 in 67f6e08

z = (PyLongObject *)PyLong_FromLong(1L);
if (z == NULL)
goto Error;

return PyLong_FromLong(0);

And so on.

Use _PyLong_GetOne() and _PyLong_GetZero() can reduce null check and might reduce minor memory usage, as they use static caches.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@hikariyo hikariyo added the type-feature A feature request or enhancement label Oct 14, 2024
@hikariyo hikariyo changed the title Use _PyLong_GetOne() and _PyLong_GetZero() in longobject.c Use _PyLong_GetOne() and _PyLong_GetZero() in Objects Oct 14, 2024
@tomasr8 tomasr8 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 14, 2024
@skirpichev skirpichev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants