String#clear has a simpler dispatch and requires no object allocation. The only reason we used String#replace before was because it was inherited from a Ruby 1.8-compatible project where String#clear was not available. --- lib/yahns/stream_input.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/yahns/stream_input.rb b/lib/yahns/stream_input.rb index eea3a0a..d32ff66 100644 --- a/lib/yahns/stream_input.rb +++ b/lib/yahns/stream_input.rb @@ -50,7 +50,7 @@ class Yahns::StreamInput # :nodoc: rv << @rbuf to_read -= @rbuf.size end - @rbuf.replace('') + @rbuf.clear end rv = nil if rv.empty? && length != 0 else @@ -137,7 +137,7 @@ class Yahns::StreamInput # :nodoc: dst << @rbuf end ensure - @rbuf.replace('') + @rbuf.clear end def eof! -- EW