Skip to content

Internal C-API: Proposal to optimize or expand helper methods in pycore_abstract.h #157199

Description

@denizguney

Feature or enhancement

Proposal:

While reviewing the internal abstract protocols in pycore_abstract.h, I noticed potential areas for improving helper functions and fast-path inline checks for object protocols.

Proposed Improvement:
To enhance readability and performance for internal C-API consumers (such as shared extensions and JIT support), we can refine or add small inline utility checks similar to _PyIndex_Check:

// Example concept for checking or optimizing internal operations
static inline int
_PyIndex_Check(PyObject *obj)
{
    PyNumberMethods *tp_as_number = Py_TYPE(obj)->tp_as_number;
    return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
}

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is providedtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions