summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2012-12-19 03:40:24 -0800
committerYukihiro "Matz" Matsumoto <[email protected]>2012-12-19 03:40:24 -0800
commit1184efe62b4fe537df6941fde43cdd56b82490bd (patch)
tree38e7764dccebc1432d89b2f4c4cbc23be1c28311
parent207de4a3b3d1f95cd0ae7d79f06ceb30654b01f5 (diff)
parent6a450a6bda0d6a3d82821a2adf9e6e2933bab86f (diff)
downloadmruby-1184efe62b4fe537df6941fde43cdd56b82490bd.tar.gz
mruby-1184efe62b4fe537df6941fde43cdd56b82490bd.zip
Merge pull request #648 from RyanScottLewis/master
Slightly faster Array#each method.
-rw-r--r--mrblib/array.rb8
1 files changed, 3 insertions, 5 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb
index 50f851fd2..3dc6b57d1 100644
--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -10,11 +10,9 @@ class Array
#
# ISO 15.2.12.5.10
def each(&block)
- idx = 0
- while(idx < length)
- block.call(self[idx])
- idx += 1
- end
+ idx, length = -1, self.length-1
+ block.call(self[idx += 1]) while(idx < length)
+
self
end