Avoid some unnecessary buffer copying in REPL.jl
Fix #5770 (testall output)

thanks to @nolta