diff options
author | Xavier Noria <fxn@hashref.com> | 2015-11-11 21:35:34 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-11 21:35:34 +0100 |
commit | 18b44ff1e485ebe4cb5801d9eaa5314d970cadd7 (patch) | |
tree | 43d348192bfa2687e022d4598027411a9a3cd67f /activesupport/lib | |
parent | 5da4be67a02cf2981d9b544ff8a9bbd073e1779e (diff) | |
download | rails-18b44ff1e485ebe4cb5801d9eaa5314d970cadd7.tar.gz rails-18b44ff1e485ebe4cb5801d9eaa5314d970cadd7.tar.bz2 rails-18b44ff1e485ebe4cb5801d9eaa5314d970cadd7.zip |
let filter_out_descendants do less passes
Whatever the inner loop selects, we already know is a descendant and
can be filtered out right away from dirs_sorted_by_nparts to skip
useless iterations.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/file_evented_update_checker.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/file_evented_update_checker.rb b/activesupport/lib/active_support/file_evented_update_checker.rb index 9c66363e9f..5e5874c014 100644 --- a/activesupport/lib/active_support/file_evented_update_checker.rb +++ b/activesupport/lib/active_support/file_evented_update_checker.rb @@ -130,22 +130,22 @@ module ActiveSupport end # Filters out directories which are descendants of others in the collection (stable). - def filter_out_descendants(directories) - return directories if directories.length < 2 + def filter_out_descendants(dirs) + return dirs if dirs.length < 2 - sorted_by_nparts = directories.sort_by { |dir| dir.each_filename.to_a.length } + dirs_sorted_by_nparts = dirs.sort_by { |dir| dir.each_filename.to_a.length } descendants = [] - until sorted_by_nparts.empty? - dir = sorted_by_nparts.shift + until dirs_sorted_by_nparts.empty? + dir = dirs_sorted_by_nparts.shift - descendants.concat sorted_by_nparts.select { |possible_descendant| - dir.ascendant_of?(possible_descendant) - } + dirs_sorted_by_nparts.reject! do |possible_descendant| + dir.ascendant_of?(possible_descendant) && descendants << possible_descendant + end end # Array#- preserves order. - directories - descendants + dirs - descendants end end end |