diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-09 03:32:45 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-09 03:32:45 +0000 |
commit | 7ea2bb32350dcf4ef075f69cbcdedbd38f11a338 (patch) | |
tree | 9e53b79c41a073e93b81d651c568ac3044f5f1ef | |
parent | 9d3c64a40a8190684155f3ee085a12a8f3dd2c72 (diff) | |
download | ruby-7ea2bb32350dcf4ef075f69cbcdedbd38f11a338.tar.gz |
* lib/prime.rb: Simplify and optimize EratosthenesSieve
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/prime.rb | 5 |
2 files changed, 7 insertions, 4 deletions
@@ -1,6 +1,10 @@ +Tue Jun 9 12:31:25 2015 Marc-Andre Lafortune <ruby-core@marc-andre.ca> + + * lib/prime.rb: Simplify and optimize EratosthenesSieve + Tue Jun 9 11:45:00 2015 Marc-Andre Lafortune <ruby-core@marc-andre.ca> - * lib/matrix.rb: Simplify and optimize EratosthenesSieve + * lib/prime.rb: Simplify and optimize EratosthenesSieve based on patch by Ajay Kumar. [Fixes GH-921] Mon Jun 8 05:09:58 2015 Koichi Sasada <ko1@atdot.net> diff --git a/lib/prime.rb b/lib/prime.rb index ef0784a385..d361e96720 100644 --- a/lib/prime.rb +++ b/lib/prime.rb @@ -436,9 +436,8 @@ class Prime end end - segment.each do |prime| - @primes.push prime unless prime.nil? - end + @primes.concat(segment.compact!) + @max_checked = segment_max end end |