From a6e4b73049666f38d338a75c1bf33863a69be9aa Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:01:19 +0200 Subject: [PATCH] Improve performance for many unresolved includes/extends Potential fix for #1126 --- lib/rdoc/mixin.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/rdoc/mixin.rb b/lib/rdoc/mixin.rb index fa8faefc15..62aebe9680 100644 --- a/lib/rdoc/mixin.rb +++ b/lib/rdoc/mixin.rb @@ -18,6 +18,7 @@ def initialize(name, comment) @name = name self.comment = comment @module = nil # cache for module if found + @module_lookup_failed = false end ## @@ -64,16 +65,10 @@ def inspect # :nodoc: # - if not found, look into the children of included modules, # in reverse inclusion order; # - if still not found, go up the hierarchy of names. - # - # This method has O(n!) behavior when the module calling - # include is referencing nonexistent modules. Avoid calling #module until - # after all the files are parsed. This behavior is due to ruby's constant - # lookup behavior. - # - # As of the beginning of October, 2011, no gem includes nonexistent modules. def module return @module if @module + return @name if @module_lookup_failed # search the current context return @name unless parent @@ -101,6 +96,7 @@ def module up = up.parent end + @module_lookup_failed = true @name end