ruby-changes:60510
From: aycabta <ko1@a...>
Date: Thu, 26 Mar 2020 17:44:34 +0900 (JST)
Subject: [ruby-changes:60510] ffbb162f1a (master): [ruby/irb] Detect multiple lines output simplify
https://git.ruby-lang.org/ruby.git/commit/?id=ffbb162f1a From ffbb162f1a052054ce2864d2971e83da10f8aa78 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 25 Feb 2020 20:32:07 +0900 Subject: [ruby/irb] Detect multiple lines output simplify The old implementation performance test code: require 'objspace' puts "%.5g MB" % (ObjectSpace.memsize_of_all * 0.001 * 0.001) /\A.*\Z/ !~ ('abc' * 20_000_000) puts "%.5g MB" % (ObjectSpace.memsize_of_all * 0.001 * 0.001) and run `time test.rb`: 2.5868 MB 62.226 MB real 0m1.307s user 0m0.452s sys 0m0.797s The new implementation performance test code: require 'objspace' puts "%.5g MB" % (ObjectSpace.memsize_of_all * 0.001 * 0.001) ('abc' * 20_000_000).include?("\n") puts "%.5g MB" % (ObjectSpace.memsize_of_all * 0.001 * 0.001) and run `time test.rb`: 2.5861 MB 62.226 MB real 0m0.132s user 0m0.088s sys 0m0.042s https://github.com/ruby/irb/commit/40d6610baf diff --git a/lib/irb.rb b/lib/irb.rb index de5af30..e73174e 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -738,7 +738,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L738 def output_value # :nodoc: str = @context.inspect_last_value - multiline_p = /\A.*\Z/ !~ str + multiline_p = str.include?("\n") if multiline_p && @context.newline_before_multiline_output? printf @context.return_format, "\n#{str}" else -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/