]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-144380: Fix incorrect type check in `buffered_iternext()` (GH-144381) ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 Feb 2026 10:29:16 +0000 (11:29 +0100)
committerGitHub <noreply@github.com>
Mon, 2 Feb 2026 10:29:16 +0000 (10:29 +0000)
gh-144380: Fix incorrect type check in `buffered_iternext()` (GH-144381)
(cherry picked from commit 40d07cad38bf3ce60f4ca03f1836e8650fe40df5)

Co-authored-by: Ruiyang Ke <me@ry.ke>
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 65d69d0d5e13d083ea27f23469f56c81081fe2f1..2e8566168de4bac0f0212958eb20a02f41b44b88 100644 (file)
@@ -1486,8 +1486,8 @@ buffered_iternext(buffered *self)
 
     _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);