[前][次][番号順一覧][スレッド一覧]

ruby-changes:56067

From: Nobuyoshi <ko1@a...>
Date: Mon, 10 Jun 2019 21:20:23 +0900 (JST)
Subject: [ruby-changes:56067] Nobuyoshi Nakada: 976c689ad4 (trunk): irb: defer requiring rdoc to improve the start up time

https://git.ruby-lang.org/ruby.git/commit/?id=976c689ad4

From 976c689ad478b8010b053aa270a28bd236b8380e Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 10 Jun 2019 21:07:24 +0900
Subject: irb: defer requiring rdoc to improve the start up time


diff --git a/lib/irb/cmd/help.rb b/lib/irb/cmd/help.rb
index 71590ee..10ec134 100644
--- a/lib/irb/cmd/help.rb
+++ b/lib/irb/cmd/help.rb
@@ -9,17 +9,18 @@ https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/help.rb#L9
 #
 #
 
-require 'rdoc/ri/driver'
-
 require_relative "nop"
 
 # :stopdoc:
 module IRB
   module ExtendCommand
     class Help < Nop
-      begin
-        Ri = RDoc::RI::Driver.new
-      rescue SystemExit
+      def execute(*names)
+        require 'rdoc/ri/driver'
+        IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new)
+      rescue LoadError, SystemExit
+        IRB::ExtendCommand::Help.remove_method(:execute)
+        # raise NoMethodError in ensure
       else
         def execute(*names)
           if names.empty?
@@ -35,6 +36,8 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/cmd/help.rb#L36
           end
           nil
         end
+      ensure
+        execute(*names)
       end
     end
   end
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 26d6728..f75dd0e 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -8,7 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L8
 #
 
 require "readline"
-require "rdoc"
+autoload :RDoc, "rdoc"
 
 module IRB
   module InputCompletor # :nodoc:
@@ -267,8 +267,8 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L267
       end
     end
 
-    RDocRIDriver = RDoc::RI::Driver.new
     PerfectMatchedProc = ->(matched) {
+      RDocRIDriver ||= RDoc::RI::Driver.new
       if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
         File.open(File.join(__dir__, 'ruby_logo.aa')) do |f|
           RDocRIDriver.page do |io|
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]