From a8c99a25802cd46b92800fd2ab1030011f8942f4 Mon Sep 17 00:00:00 2001 From: Blake Mesdag Date: Tue, 12 Apr 2016 08:29:33 -0400 Subject: Use a single memoized loop to find max mtime in ActiveSupport::FileUpdateChecker#max_mtime --- activesupport/lib/active_support/file_update_checker.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 8708a502e6..eaa5fc56a7 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -112,7 +112,18 @@ 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) + + if time < time_now && time > max_time + max_time = time + end + end + + max_time.object_id == time_at_zero.object_id ? nil : max_time end def compile_glob(hash) -- cgit v1.2.3 From fcde948e43e07d2c4e32988e05f5920501a26364 Mon Sep 17 00:00:00 2001 From: Blake Mesdag Date: Tue, 12 Apr 2016 09:46:25 -0400 Subject: Use Time#compare_without_coercion for super speed --- activesupport/lib/active_support/file_update_checker.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index eaa5fc56a7..4f0a2dedc5 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -118,7 +118,12 @@ module ActiveSupport paths.each do |path| time = File.mtime(path) - if time < time_now && time > max_time + # 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 -- cgit v1.2.3