From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7FF11211B4 for ; Sat, 5 Jan 2019 21:04:31 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] wbuf: use IO#write directly in Ruby 2.5+ for writev Date: Sat, 5 Jan 2019 21:04:31 +0000 Message-Id: <20190105210431.26013-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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