From a646584284f63397d05941eaf29f2e7d4fc6d8ff Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 24 Jul 2018 10:13:38 +0200 Subject: [PATCH] use a type parameter for stream in EachLine, improves performance --- base/io.jl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/base/io.jl b/base/io.jl index b54066137bd37..594a64393d3d3 100644 --- a/base/io.jl +++ b/base/io.jl @@ -842,14 +842,13 @@ read(s::IO, T::Type) = error("The IO stream does not support reading objects of ## high-level iterator interfaces ## -struct EachLine - stream::IO +struct EachLine{IOT <: IO} + stream::IOT ondone::Function keep::Bool - - EachLine(stream::IO=stdin; ondone::Function=()->nothing, keep::Bool=false) = - new(stream, ondone, keep) end +EachLine(stream::IO=stdin; ondone::Function=()->nothing, keep::Bool=false) = + EachLine(stream, ondone, keep) """ eachline(io::IO=stdin; keep::Bool=false) @@ -898,9 +897,9 @@ function iterate(itr::EachLine, state=nothing) (readline(itr.stream, keep=itr.keep), nothing) end -eltype(::Type{EachLine}) = String +eltype(::Type{<:EachLine}) = String -IteratorSize(::Type{EachLine}) = SizeUnknown() +IteratorSize(::Type{<:EachLine}) = SizeUnknown() # IOStream Marking # Note that these functions expect that io.mark exists for