Skip to content

Commit

Permalink
Standardize breadth-first loops
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed May 12, 2024
1 parent 33fe4a2 commit d07be7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/zeitwerk/loader/eager_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def load_file(path)
log("eager load directory #{dir} start") if logger

queue = [[dir, namespace]]
while to_eager_load = queue.shift
dir, namespace = to_eager_load
until queue.empty?
dir, namespace = queue.shift

ls(dir) do |basename, abspath|
next if honour_exclusions && eager_load_exclusions.member?(abspath)
Expand Down Expand Up @@ -210,7 +210,9 @@ def load_file(path)
next_dirs = []

suffix.split("::").each do |segment|
while dir = dirs.shift
until dirs.empty?
dir = dirs.shift

ls(dir) do |basename, abspath|
next unless dir?(abspath)

Expand Down
4 changes: 3 additions & 1 deletion lib/zeitwerk/loader/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ module Zeitwerk::Loader::Helpers
private def has_at_least_one_ruby_file?(dir)
to_visit = [dir]

while dir = to_visit.shift
until to_visit.empty?
dir = to_visit.shift

ls(dir) do |_basename, abspath|
if dir?(abspath)
to_visit << abspath
Expand Down

0 comments on commit d07be7d

Please sign in to comment.