* [PATCH] stream_input: favor str.clear instead of str.replace('')
@ 2014-10-18 11:02 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2014-10-18 11:02 UTC (permalink / raw)
To: yahns-public
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2014-10-18 11:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-18 11:02 [PATCH] stream_input: favor str.clear instead of str.replace('') Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).