From 43e64b85852e72b1e7f28bdd0f33eaec57b906c8 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 24 Dec 2017 01:52:21 +0000 Subject: [PATCH] lib/irb.rb: simplified backtrace filtering git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61434 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/irb.rb | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/irb.rb b/lib/irb.rb index 31190ba649..183ad813ee 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -508,31 +508,24 @@ module IRB lasts = [] levels = 0 if exc.backtrace - filtered_line_count = 0 - exc.backtrace.each_with_index do |m, i| - num_str = (i + 1 - filtered_line_count).to_s.rjust(9, ' ') - m = @context.workspace.filter_backtrace(m) unless irb_bug - if m - if messages.size < @context.back_trace_limit - messages.push "#{num_str}: from "+m - else - lasts.push "#{num_str}: from "+m - if lasts.size > @context.back_trace_limit - lasts.shift - levels += 1 - end - end - else - filtered_line_count += 1 + count = 0 + exc.backtrace.each do |m| + m = @context.workspace.filter_backtrace(m) or next unless irb_bug + m = sprintf("%9d: from %s", (count += 1), m) + if messages.size < @context.back_trace_limit + messages.push(m) + elsif lasts.size < @context.back_trace_limit + lasts.push(m).shift + levels += 1 end end end print "Traceback (most recent call last):\n" unless lasts.empty? - print lasts.reverse.join("\n"), "\n" + puts lasts.reverse printf "... %d levels...\n", levels if levels > 0 end - print messages.reverse.join("\n"), "\n" + puts messages.reverse print exc.class, ": ", exc, "\n" print "Maybe IRB bug!\n" if irb_bug end