From 95d7a204617ec789e52654cbfefff6d092cc232e Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Fri, 21 Mar 2025 12:22:22 +0100 Subject: [PATCH] iobuffer: copyline: type assert `Int` to prevent invalidation Should prevent much invalidation stemming from `MethodInstance`s for * `readline()` * `readlines()` * `Base.run_fallback_repl(::Bool)` * `Base.repl_main(::Any)` * `Base._start()` In each case the issue is the access of the nonconcretely-typed global variable `stdin::IO`. --- base/iobuffer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/iobuffer.jl b/base/iobuffer.jl index 7e309b9ad586c..144b0a20568e9 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -643,7 +643,7 @@ function _copyline(out::IO, io::GenericIOBuffer; keep::Bool=false) data = view(io.data, io.ptr:io.size) # note: findfirst + copyto! is much faster than a single loop # except for nout ≲ 20. A single loop is 2x faster for nout=5. - nout = nread = something(findfirst(==(0x0a), data), length(data)) + nout = nread = something(findfirst(==(0x0a), data), length(data))::Int if !keep && nout > 0 && data[nout] == 0x0a nout -= 1 nout > 0 && data[nout] == 0x0d && (nout -= 1)