Skip to content

Commit

Permalink
Using sets instead of arrays and empty? instead of any?
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrias committed Dec 16, 2024
1 parent 736e21b commit 8c57404
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/zeitwerk/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,17 @@ def all_dirs
# If manual incepted namespaces are present we skip the default behavior
# and we will only incept the manually defined namespaces for improved
# performance
if manual_incepted_namespaces.any?
if manual_incepted_namespaces.include?(cref.cname.name)
Registry.register_inception(cref.path, abspath, self)
end
else
if manual_incepted_namespaces.empty?
# This operation can impact performance in big codebases since it will
# be evaluated for every single auoloaded constant.
# See why in the documentation of Zeitwerk::Registry.inceptions.
unless cref.autoload?
Registry.register_inception(cref.path, abspath, self)
end
else
if manual_incepted_namespaces.include?(cref.cname.name)
Registry.register_inception(cref.path, abspath, self)
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/zeitwerk/loader/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Zeitwerk::Loader::Config
# @sig #call | #debug | nil
attr_accessor :logger

# @sig nil
# @sig Set[String]
attr_accessor :manual_incepted_namespaces

# Absolute paths of the root directories, mapped to their respective root namespaces:
Expand Down Expand Up @@ -89,7 +89,7 @@ module Zeitwerk::Loader::Config
def initialize
@inflector = Zeitwerk::Inflector.new
@logger = self.class.default_logger
@manual_incepted_namespaces = []
@manual_incepted_namespaces = Set.new
@tag = SecureRandom.hex(3)
@initialized_at = Time.now
@roots = {}
Expand Down

0 comments on commit 8c57404

Please sign in to comment.