aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb.rb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-06-30 18:41:56 +0100
committergit <svn-admin@ruby-lang.org>2023-06-30 17:42:00 +0000
commit136fcd5118b844bb8399d69dc44414cb3bd2028a (patch)
treedd5fb9e08bf8d97423ad981e71f6ae8fc527f65a /lib/irb.rb
parent94788a6d13a136f28daca2a51ad7945c52b2311d (diff)
downloadruby-136fcd5118b844bb8399d69dc44414cb3bd2028a.tar.gz
[ruby/irb] Reduce internal operations' exposure to benchmarking
(https://github.com/ruby/irb/pull/618) * Test last value is assigned with measure enabled * Remove unnecessary `result` variable `Context#evaluate` always assigns the result of the evaluation to `_` so we don't need to do it in `Irb#eval_input`. * Move benchmarking logic into `Context#evaluate` Current location of the benchmarking logic is too high up and includes operations like command loading and argument transformation, which should be excluded. So this commit moves it into `Context#evaluate` to reduce the noise. We don't move it further down to `Workspace#evaluate` because `Context` is an argument of the measure block, which is not available in `Workspace`.
Diffstat (limited to 'lib/irb.rb')
-rw-r--r--lib/irb.rb20
1 files changed, 2 insertions, 18 deletions
diff --git a/lib/irb.rb b/lib/irb.rb
index ed79160b24..64c716fd4c 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -558,26 +558,10 @@ module IRB
@scanner.each_top_level_statement do |line, line_no|
signal_status(:IN_EVAL) do
begin
- if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
- IRB.set_measure_callback
- end
# Assignment expression check should be done before evaluate_line to handle code like `a /2#/ if false; a = 1`
is_assignment = assignment_expression?(line)
- if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
- result = nil
- last_proc = proc{ result = evaluate_line(line, line_no) }
- IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
- _name, callback, arg = item
- proc {
- callback.(@context, line, line_no, arg) do
- chain.call
- end
- }
- }.call
- @context.set_last_value(result)
- else
- evaluate_line(line, line_no)
- end
+ evaluate_line(line, line_no)
+
if @context.echo?
if is_assignment
if @context.echo_on_assignment?