Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Buffer Protocol support to int.from_bytes #132108

Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement
@cmaloney

Description

@cmaloney

Feature or enhancement

Proposal:

Currentlyint.from_bytes takes aPyObject* and alwaysconverts it to abytes usingPyObject_Bytes. When a "bytes-like" object is passed in, such asbytearray in_pylong, thePyObject_Bytes function has to make a newPyBytes* and copy the data from the bytes-like into it. Utilize the buffer protocol, with a fallback to PyObject_Bytes, to remove that object allocation and copy making the conversion faster.

I think the fallback is needed becausePyObject_Bytes supports additional methods, such as.__bytes__() to construct thebytes, which should remain supported. That means need to keep doingbytes as bytes_obj: object in Argument Clinic, rather thanbytes as bytes_obj: Py_buffer.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp