ruby-changes:35015
From: glass <ko1@a...>
Date: Thu, 7 Aug 2014 23:32:08 +0900 (JST)
Subject: [ruby-changes:35015] glass:r47097 (trunk): * lib/open3.rb: avoid unnecessary write if stdin_data is empty.
glass 2014-08-07 23:31:54 +0900 (Thu, 07 Aug 2014) New Revision: 47097 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47097 Log: * lib/open3.rb: avoid unnecessary write if stdin_data is empty. Modified files: trunk/ChangeLog trunk/lib/open3.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47096) +++ ChangeLog (revision 47097) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Aug 7 23:25:29 2014 Masaki Matsushita <glass.saga@g...> + + * lib/open3.rb: avoid unnecessary write if stdin_data is empty. + Thu Aug 7 21:42:49 2014 Masaki Suketa <masaki.suketa@n...> * ext/win32ole/win32ole_typelib.c (foletypelib_version): return Index: lib/open3.rb =================================================================== --- lib/open3.rb (revision 47096) +++ lib/open3.rb (revision 47097) @@ -296,16 +296,18 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L296 # End # image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true) # - def capture2(*cmd, stdin_data: '', binmode: false, **opts) + def capture2(*cmd, stdin_data: nil, binmode: false, **opts) popen2(*cmd, opts) {|i, o, t| if binmode i.binmode o.binmode end out_reader = Thread.new { o.read } - begin - i.write stdin_data - rescue Errno::EPIPE + if stdin_data + begin + i.write stdin_data + rescue Errno::EPIPE + end end i.close [out_reader.value, t.value] @@ -329,16 +331,18 @@ module Open3 https://github.com/ruby/ruby/blob/trunk/lib/open3.rb#L331 # # capture make log # make_log, s = Open3.capture2e("make") # - def capture2e(*cmd, stdin_data: '', binmode: false, **opts) + def capture2e(*cmd, stdin_data: nil, binmode: false, **opts) popen2e(*cmd, opts) {|i, oe, t| if binmode i.binmode oe.binmode end outerr_reader = Thread.new { oe.read } - begin - i.write stdin_data - rescue Errno::EPIPE + if stdin_data + begin + i.write stdin_data + rescue Errno::EPIPE + end end i.close [outerr_reader.value, t.value] -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/