GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing github.com — gh-129813, PEP 782: Use PyBytesWriter in bufferedio.c by vstinner · Pull Request #138954 · python/cpython Conversation
|
|
Benchmark: import pyperf import os file = open(__file__, "rb") def func(): file.seek(0) for _ in range(100): file.read1(1) runner = pyperf.Runner() runner.bench_func('bench', func) file.close() Result: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
cc @cmaloney |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
👍 looks good to me; could make the PyBytesWriter a little later and save some cleanup code (but would mean making it during the buffered lock)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if (n == 0) | ||
| return PyBytes_FromStringAndSize(NULL, 0); | ||
| if (n == 0) { | ||
| return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This comes up fairly frequently in the I/O code, thinking of making a _Py_EMPTY_BYTES internal macro for it (separate from this PR)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do you mean a macro specific to the _io module?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was thinking pycore_bytesobject.h; currently shows up 24 times across the CPython source code. BufferedIO and a couple other places also use a pattern: (PyObject *)&_Py_SINGLETON(bytes_empty)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Move PyBytesWriter_Create() call
|
Merged, thanks for the review and suggestions @cmaloney. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.