From e0adfa82c05f9c975005f102b4bcaebfcd17d241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 9 Aug 2009 19:03:09 +0200 Subject: Optimize Range#sum only for integers [#2489] --- activesupport/lib/active_support/core_ext/enumerable.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/enumerable.rb') diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index d68eef8c23..42686cfbd5 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -113,9 +113,10 @@ module Enumerable end class Range #:nodoc: - # Optimize range sum to use arithmetic progression if a block is not given. + # Optimize range sum to use arithmetic progression if a block is not given and + # we have a range of numeric values. def sum(identity=0, &block) - return super if block_given? + return super if block_given? || !(first.instance_of?(Integer) && last.instance_of?(Integer)) actual_last = exclude_end? ? (last - 1) : last (actual_last - first + 1) * (actual_last + first) / 2 end -- cgit v1.2.3