Cody Maloney
Cody Maloney
I'll see if I can make a largely performance neutral version that checks `__bytes__` before using buffer protocol. The potential disconnect between `__bytes__()` and `__buffer__()` concerns me, feels like a...
Some back pieces for reference: `__bytes__` was added to `bytes()` in 3.11 https://github.com/python/cpython/issues/68422 while type hints were being worked on. The buffer protocol was before that in 3.0 (pep-3118).
Another edge case around these, `__bytes__()` is only used once and must return only a object that inherits from `bytes`, on which `PyBytes_AsString` is used that returns the `ob_sval` inline...
Created a branch which matches resolution order of `PyObject_Bytes` which gives a small performance improvement (~2%, avoids touching reference count) in the common from exact bytes case, keeps most the...
Updated to use `PyBytes_CheckExact` first as that case is common and it speeds up `bytes` relative to main. Also tested some bigger byte strings, added speedup note around 128, 256,...
Anything I can do to help close out this PR?
ping @serhiy-storchaka : Trying to find ways to close out this PR. I'm happy to update this to match the past resolution order or leave as is if prior review...
A more general solution would definitely be nice. `bytearray` (mutable block of bytes) + `int.from_bytes` shows up in the performance of code I've been working on and would be nice...
> LGTM. The latest PR is now backward compatible. > > ```python > >>> class X(bytes): > ... def __bytes__(self): > ... return b'X' > ... > >>> int.from_bytes(X(b'a')) >...
Going through the TextIO code, there's quite a few related cases it currently looks like. Making sure no new code is added between a call which could invalidate `self->buffer` and...