mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mrblib: use yield instead of block.call for iteration methods
Replace block.call(x) with yield x in core iteration methods to take advantage of the new OP_BLKCALL optimization. This improves Integer#times by 13% and Array#each by 7%. Methods updated: - Integer#times, Integer#upto, Integer#downto - Array#each, Array#each_index Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -17,7 +17,7 @@ class Array
|
||||
|
||||
idx = 0
|
||||
while idx < length
|
||||
block.call(self[idx])
|
||||
yield self[idx]
|
||||
idx += 1
|
||||
end
|
||||
self
|
||||
@@ -37,7 +37,7 @@ class Array
|
||||
|
||||
idx = 0
|
||||
while idx < length
|
||||
block.call(idx)
|
||||
yield idx
|
||||
idx += 1
|
||||
end
|
||||
self
|
||||
|
||||
+3
-3
@@ -49,7 +49,7 @@ class Integer
|
||||
|
||||
i = self.to_i
|
||||
while i >= num
|
||||
block.call(i)
|
||||
yield i
|
||||
i -= 1
|
||||
end
|
||||
self
|
||||
@@ -74,7 +74,7 @@ class Integer
|
||||
|
||||
i = 0
|
||||
while i < self
|
||||
block.call(i)
|
||||
yield i
|
||||
i += 1
|
||||
end
|
||||
self
|
||||
@@ -90,7 +90,7 @@ class Integer
|
||||
|
||||
i = self.to_i
|
||||
while i <= num
|
||||
block.call(i)
|
||||
yield i
|
||||
i += 1
|
||||
end
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user