| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead. |
Sorry, something went wrong.
|
|
||
| if (PyList_Append(result, line) < 0) { | ||
| Py_DECREF(line); | ||
| if (_PyList_AppendTakeRef((PyListObject *)result, line) < 0) { |
There was a problem hiding this comment.
The call to PyObject_Size(line) should be moved up. After the _PyList_AppendTakeRef we are no longer have a valid reference to line.
Sorry, something went wrong.
| /* XXX special-casing this made sense in the Python version in order | ||
| to remove the bytecode interpretation overhead, but it could | ||
| probably be removed here. */ | ||
| PyObject *ret = PyObject_CallMethodObjArgs(result, &_Py_ID(extend), |
There was a problem hiding this comment.
The changes in this PR will not matter for calls like f.readlines() since that ends up in the fast path here. We could change the call here to PyObject_CallMethodOneArg which might be faster, but that is for another PR.
Sorry, something went wrong.
| @@ -0,0 +1,2 @@ | |||
| Improve the performance of :meth:`io.IOBase.readlines` by avoiding | |||
There was a problem hiding this comment.
Can you provide benchmarks where this change has a positive effect for real-world cases? I suspect the change might be too minimal to warrant acceptance of the PR.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR optimizes _io.IOBase.readlines() by using
_PyList_AppendTakeRef() when adding lines to the result list.
Previously, each line was added with PyList_Append(), which creates an
extra temporary reference. The new code transfers the existing reference
directly to the result list, avoiding an unnecessary reference-count
increment/decrement pair.
The order of operations is unchanged: the line is added before its length
is inspected, preserving the prior behavior.
Tests: