From 97698606de78cef4bd2202ed04ce98d3a5f2d629 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 31 Mar 2015 18:43:44 -0700 Subject: Only coerce time when comparing if necessary In dev, ActiveSupport::FileUpdateChecker#max_mtime triggers many time comparisons. Time#to_time is quite a bit slower than not doing it, so we should avoid it if possible. --- activesupport/lib/active_support/core_ext/time/calculations.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 6f1b653639..1ce68ea7c7 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -246,8 +246,10 @@ class Time # Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances # can be chronologically compared with a Time def compare_with_coercion(other) - # we're avoiding Time#to_datetime cause it's expensive - if other.is_a?(Time) + # we're avoiding Time#to_datetime and Time#to_time because they're expensive + if other.class == Time + compare_without_coercion(other) + elsif other.is_a?(Time) compare_without_coercion(other.to_time) else to_datetime <=> other -- cgit v1.2.3