diff options
author | Xavier Noria <fxn@hashref.com> | 2016-04-12 08:11:28 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-04-12 08:11:28 -0700 |
commit | d6769f4d106ee6f9a3bbad925098260bdac5f799 (patch) | |
tree | 7fd46b0d69c341169ef470d0e7c2afcdd44ed8e2 /activesupport/lib | |
parent | db9bc8097399aab9c866175b12e9e099b6c83ffa (diff) | |
parent | fcde948e43e07d2c4e32988e05f5920501a26364 (diff) | |
download | rails-d6769f4d106ee6f9a3bbad925098260bdac5f799.tar.gz rails-d6769f4d106ee6f9a3bbad925098260bdac5f799.tar.bz2 rails-d6769f4d106ee6f9a3bbad925098260bdac5f799.zip |
Merge pull request #24520 from BlakeMesdag/activesupport-fileupdate-checker-mtime-optimization
Use a single loop in ActiveSupport:FileUpdateChecker#max_mtime
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/file_update_checker.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 8708a502e6..4f0a2dedc5 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -112,7 +112,23 @@ module ActiveSupport # reloading is not triggered. def max_mtime(paths) time_now = Time.now - paths.map {|path| File.mtime(path)}.reject {|mtime| time_now < mtime}.max + time_at_zero = Time.at(0) + max_time = time_at_zero + + paths.each do |path| + time = File.mtime(path) + + # This avoids ActiveSupport::CoreExt::Time#time_with_coercion + # which is super slow when comparing two Time objects + # + # Equivalent Ruby: + # time < time_now && time > max_time + if time.compare_without_coercion(time_now) < 0 && time.compare_without_coercion(max_time) > 0 + max_time = time + end + end + + max_time.object_id == time_at_zero.object_id ? nil : max_time end def compile_glob(hash) |