]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-144380: Fix incorrect type check in `buffered_iternext()` (#144381)
authorRuiyang Ke <me@ry.ke>
Mon, 2 Feb 2026 10:04:18 +0000 (02:04 -0800)
committerGitHub <noreply@github.com>
Mon, 2 Feb 2026 10:04:18 +0000 (15:34 +0530)
Misc/NEWS.d/next/Library/2026-02-01-15-25-00.gh-issue-144380.U7py_s.rst [new file with mode: 0644]
Modules/_io/bufferedio.c

diff --git a/Misc/NEWS.d/next/Library/2026-02-01-15-25-00.gh-issue-144380.U7py_s.rst b/Misc/NEWS.d/next/Library/2026-02-01-15-25-00.gh-issue-144380.U7py_s.rst
new file mode 100644 (file)
index 0000000..4b5b1b3
--- /dev/null
@@ -0,0 +1 @@
+Improve performance of :class:`io.BufferedReader` line iteration by ~49%.
index 6d779abd89ca84b4ae27ca6c84798afe47493ee3..0fdae7b2d210040bb7ab28db6f7c684388291088 100644 (file)
@@ -1505,8 +1505,8 @@ buffered_iternext(PyObject *op)
 
     _PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
     tp = Py_TYPE(self);
-    if (Py_IS_TYPE(tp, state->PyBufferedReader_Type) ||
-        Py_IS_TYPE(tp, state->PyBufferedRandom_Type))
+    if (tp == state->PyBufferedReader_Type ||
+        tp == state->PyBufferedRandom_Type)
     {
         /* Skip method call overhead for speed */
         line = _buffered_readline(self, -1);