diff options
author | Aaron Jensen <aaronjensen@gmail.com> | 2015-03-31 18:43:44 -0700 |
---|---|---|
committer | Aaron Jensen <aaronjensen@gmail.com> | 2015-03-31 18:43:44 -0700 |
commit | 97698606de78cef4bd2202ed04ce98d3a5f2d629 (patch) | |
tree | 839921aa804d0ab2087a38fe0ba47615ade46cbc | |
parent | baa176e3f043dbea4e64dbc25dfa1b7ee02a9831 (diff) | |
download | rails-97698606de78cef4bd2202ed04ce98d3a5f2d629.tar.gz rails-97698606de78cef4bd2202ed04ce98d3a5f2d629.tar.bz2 rails-97698606de78cef4bd2202ed04ce98d3a5f2d629.zip |
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.
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 6 |
1 files changed, 4 insertions, 2 deletions
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 |