This project is archived and is in readonly mode.
Enumerable#sum should not rely on size
-
Lee Hambley
+1
-
CancelProfileIsBroken
- Tag changed from enumerable, patch, sum to bugmash, enumerable, patch, sum
-
Josh Sharpe
+1, patch applies, tests pass, and makes sense to me
-
Renaud Kern
patch and test pass. It works with Range, Array and Set. It's more consistent.
-
José Valim
Patch and tests pass, I'm just not sure if we should optimize ranges sum to use Arithmetic Progression sum. This way we would avoid instantiate and iterate through all the collection:
class Range def sum(identity=0, &block) if block_given map(&block).sum(identity) else (last - first + 1) * (last + first) / 2 end end end Range.new(1, 4).sum #=> 10 Range.new(1, 10000).sum #=> 50005000 -
Dan Pickett
+1 verified
I like Jose's optimization idea for range as well.
-
Jeremy Kemper
- State changed from new to committed
- Tag changed from bugmash, enumerable, patch, sum to enumerable, patch, sum
- Milestone changed from 2.x to 2.3.4
2-3-stable: 819c347f436f54acea5821289c6340da863bf138
master: 29096268ccce2b13e1490c8b673ffe0b498555fc
José, that'd make a nice followup patch!
-
Repository
(from [29096268ccce2b13e1490c8b673ffe0b498555fc]) Enumerable#sum now works will all enumerables, even if they don't respond to :size
[#2489 Enumerable#sum should not rely on size state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/29096268ccce2b13e1490c8b673ffe... -
Repository
(from [819c347f436f54acea5821289c6340da863bf138]) Enumerable#sum now works will all enumerables, even if they don't respond to :size
[#2489 Enumerable#sum should not rely on size state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/819c347f436f54acea5821289c6340... -
Repository
(from [1bd4d1c67459a91415ee73a8f55d2309c0d62a87]) Optimize Range#sum to use arithmetic progression when a block is not given [#2489 Enumerable#sum should not rely on size].
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/1bd4d1c67459a91415ee73a8f55d23... -
Repository
(from [e0adfa82c05f9c975005f102b4bcaebfcd17d241]) Optimize Range#sum only for integers [#2489 Enumerable#sum should not rely on size] http://github.com/rails/rails/commit/e0adfa82c05f9c975005f102b4bcae...
-
Repository
(from [ae47f7575da3dc3c74fa63136d00492ba4beb278]) Improving test coverage for Range#sum [#2489 Enumerable#sum should not rely on size]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/ae47f7575da3dc3c74fa63136d0049...
