Skip to content

Commit

Permalink
Improve performance for many unresolved includes/extends
Browse files Browse the repository at this point in the history
Potential fix for ruby#1126
  • Loading branch information
Earlopain committed Jun 27, 2024
1 parent 4b84660 commit a6e4b73
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/rdoc/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down Expand Up @@ -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 <code>O(n!)</code> 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
Expand Down Expand Up @@ -101,6 +96,7 @@ def module
up = up.parent
end

@module_lookup_failed = true
@name
end

Expand Down

0 comments on commit a6e4b73

Please sign in to comment.