Skip to content

Commit b1278b7

Browse files
committed
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.
1 parent a1406b1 commit b1278b7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/irb/input-method.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,13 @@ def initialize
296296
end
297297
Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
298298
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
299+
299300
if IRB.conf[:USE_AUTOCOMPLETE]
300-
Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
301+
begin
302+
require 'rdoc'
303+
Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
304+
rescue LoadError
305+
end
301306
end
302307
end
303308

@@ -321,11 +326,6 @@ def auto_indent(&block)
321326
[195, 164], # The "ä" that appears when Alt+d is pressed on xterm.
322327
[226, 136, 130] # The "∂" that appears when Alt+d in pressed on iTerm2.
323328
]
324-
begin
325-
require 'rdoc'
326-
rescue LoadError
327-
return nil
328-
end
329329

330330
if just_cursor_moving and completion_journey_data.nil?
331331
return nil

0 commit comments

Comments
 (0)