diff options
| author | Christopher Aue <[email protected]> | 2017-07-30 13:19:31 +0200 |
|---|---|---|
| committer | Christopher Aue <[email protected]> | 2017-07-30 13:19:31 +0200 |
| commit | 3359b86ec7284234ae088ab682f82a0603029c34 (patch) | |
| tree | 0e6e5f5dcb967d3a874a4d4f442bc4147818d98c /mrblib | |
| parent | c8fdab8725d58375ccdbd9816e48fdb021a199d4 (diff) | |
| download | mruby-3359b86ec7284234ae088ab682f82a0603029c34.tar.gz mruby-3359b86ec7284234ae088ab682f82a0603029c34.zip | |
Improved speed of enumeration methods
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/array.rb | 6 | ||||
| -rw-r--r-- | mrblib/hash.rb | 30 | ||||
| -rw-r--r-- | mrblib/numeric.rb | 8 | ||||
| -rw-r--r-- | mrblib/range.rb | 2 |
4 files changed, 23 insertions, 23 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb index be98f217e..5b9ee47c0 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -11,7 +11,7 @@ class Array # # ISO 15.2.12.5.10 def each(&block) - return to_enum :each unless block_given? + return to_enum :each unless block idx = 0 while idx < length @@ -27,7 +27,7 @@ class Array # # ISO 15.2.12.5.11 def each_index(&block) - return to_enum :each_index unless block_given? + return to_enum :each_index unless block idx = 0 while idx < length @@ -44,7 +44,7 @@ class Array # # ISO 15.2.12.5.7 def collect!(&block) - return to_enum :collect! unless block_given? + return to_enum :collect! unless block self.each_index { |idx| self[idx] = block.call(self[idx]) } self diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 4727b0870..6b4803ccb 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -84,7 +84,7 @@ class Hash # # ISO 15.2.13.4.9 def each(&block) - return to_enum :each unless block_given? + return to_enum :each unless block keys = self.keys vals = self.values @@ -117,7 +117,7 @@ class Hash # # ISO 15.2.13.4.10 def each_key(&block) - return to_enum :each_key unless block_given? + return to_enum :each_key unless block self.keys.each{|k| block.call(k)} self @@ -143,7 +143,7 @@ class Hash # # ISO 15.2.13.4.11 def each_value(&block) - return to_enum :each_value unless block_given? + return to_enum :each_value unless block self.keys.each{|k| block.call(self[k])} self @@ -224,12 +224,12 @@ class Hash # # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing. # - def reject!(&b) - return to_enum :reject! unless block_given? + def reject!(&block) + return to_enum :reject! unless block keys = [] self.each{|k,v| - if b.call([k, v]) + if block.call([k, v]) keys.push(k) end } @@ -255,12 +255,12 @@ class Hash # # 1.8/1.9 Hash#reject returns Hash; ISO says nothing. # - def reject(&b) - return to_enum :reject unless block_given? + def reject(&block) + return to_enum :reject unless block h = {} self.each{|k,v| - unless b.call([k, v]) + unless block.call([k, v]) h[k] = v end } @@ -277,12 +277,12 @@ class Hash # # 1.9 Hash#select! returns Hash; ISO says nothing. # - def select!(&b) - return to_enum :select! unless block_given? + def select!(&block) + return to_enum :select! unless block keys = [] self.each{|k,v| - unless b.call([k, v]) + unless block.call([k, v]) keys.push(k) end } @@ -308,12 +308,12 @@ class Hash # # 1.9 Hash#select returns Hash; ISO says nothing # - def select(&b) - return to_enum :select unless block_given? + def select(&block) + return to_enum :select unless block h = {} self.each{|k,v| - if b.call([k, v]) + if block.call([k, v]) h[k] = v end } diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb index 975ad973f..89401a084 100644 --- a/mrblib/numeric.rb +++ b/mrblib/numeric.rb @@ -45,7 +45,7 @@ module Integral # # ISO 15.2.8.3.15 def downto(num, &block) - return to_enum(:downto, num) unless block_given? + return to_enum(:downto, num) unless block i = self.to_i while i >= num @@ -70,7 +70,7 @@ module Integral # # ISO 15.2.8.3.22 def times &block - return to_enum :times unless block_given? + return to_enum :times unless block i = 0 while i < self @@ -86,7 +86,7 @@ module Integral # # ISO 15.2.8.3.27 def upto(num, &block) - return to_enum(:upto, num) unless block_given? + return to_enum(:upto, num) unless block i = self.to_i while i <= num @@ -102,7 +102,7 @@ module Integral # def step(num=nil, step=1, &block) raise ArgumentError, "step can't be 0" if step == 0 - return to_enum(:step, num, step) unless block_given? + return to_enum(:step, num, step) unless block i = if num.kind_of? Float then self.to_f else self end if num == nil diff --git a/mrblib/range.rb b/mrblib/range.rb index 3322af5f1..5bd2521e8 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -10,7 +10,7 @@ class Range # # ISO 15.2.14.4.4 def each(&block) - return to_enum :each unless block_given? + return to_enum :each unless block val = self.first last = self.last |
