* [PATCH] wbuf: use IO#write directly in Ruby 2.5+ for writev
@ 2019-01-05 21:04 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-01-05 21:04 UTC (permalink / raw)
To: yahns-public
Slowly removing kgio dependencies...
---
lib/yahns/wbuf.rb | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index 3abc5f9..d3552b3 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -31,6 +31,7 @@
class Yahns::Wbuf # :nodoc:
include Yahns::WbufCommon
attr_reader :busy
+ IO_WRITEV = RUBY_VERSION.to_r >= 2.5 # IO#write uses writev
def initialize(body, persist)
@tmpio = nil
@@ -40,9 +41,15 @@ def initialize(body, persist)
@busy = false
end
- def wbuf_writev(buf)
- @tmpio.kgio_writev(buf)
- buf.inject(0) { |n, s| n += s.size }
+ if IO_WRITEV
+ def wbuf_writev(buf)
+ @tmpio.write(*buf)
+ end
+ else
+ def wbuf_writev(buf)
+ @tmpio.kgio_writev(buf)
+ buf.inject(0) { |n, s| n += s.size }
+ end
end
def wbuf_write(c, buf)
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-01-05 21:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-05 21:04 [PATCH] wbuf: use IO#write directly in Ruby 2.5+ for writev Eric Wong
Code repositories for project(s) associated with this public inbox
http://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).