Skip to content

bytes(bytes) is inefficient #2125

Closed
Closed

Description

@edwardycl

Feature

bytes object is immutable, so constructing a new bytes object from another bytes object doesn't need copying.
However, PyBytes and PyByteArray share PyBytesInner implementation, causing an unnecessary copying of immutable data.

CPython:

>>> b = b'foo'
>>> bytes(b) is b
True

RustPython:

>>> b = b'foo'
>>> bytes(b) is b
False

Python Documentation

https://docs.python.org/3/library/stdtypes.html#bytes-objects

Activity

  1. added
    C-compatA discrepancy between RustPython and CPython
    on Aug 17, 2020
  2. awoimbee commented on Oct 23, 2020

    @awoimbee
    Contributor

    Fixed by #2284
    @qingshi163 you should use github keywords (Fixes #<issue number>) ;)

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

    C-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions