aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorAaron Jensen <aaronjensen@gmail.com>2015-03-31 18:43:44 -0700
committerAaron Jensen <aaronjensen@gmail.com>2015-03-31 18:43:44 -0700
commit97698606de78cef4bd2202ed04ce98d3a5f2d629 (patch)
tree839921aa804d0ab2087a38fe0ba47615ade46cbc /activesupport/lib/active_support/core_ext
parentbaa176e3f043dbea4e64dbc25dfa1b7ee02a9831 (diff)
downloadrails-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.
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb6
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