From b7622d792dde7922692de6fcf43bd87cd7faa97b Mon Sep 17 00:00:00 2001 From: st0012 Date: Tue, 18 Oct 2022 10:08:24 +0100 Subject: [PATCH] [ruby/irb] Move require out of repeated execution path SHOW_DOC_DIALOG will be called repeatedly whenever the corresponding key is pressed, but we only need to require rdoc once. So ideally the require can be put outside of the proc. And because when rdoc is not available the entire proc will be nonfunctional, we can stop registering the SHOW_DOC_DIALOG if we failed to require rdoc. https://github.com/ruby/irb/commit/b1278b7320 --- lib/irb/input-method.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index b0110dd09b..5f13971a43 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -296,8 +296,13 @@ module IRB end Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE] + if IRB.conf[:USE_AUTOCOMPLETE] - Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT) + begin + require 'rdoc' + Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT) + rescue LoadError + end end end @@ -321,11 +326,6 @@ module IRB [195, 164], # The "ä" that appears when Alt+d is pressed on xterm. [226, 136, 130] # The "∂" that appears when Alt+d in pressed on iTerm2. ] - begin - require 'rdoc' - rescue LoadError - return nil - end if just_cursor_moving and completion_journey_data.nil? return nil