Skip to content

Commit a28e3da

Browse files
committed
[GR-30441] Add LoopConditionProfile for Range#each
PullRequest: truffleruby/2646
2 parents 8fe6598 + 8083440 commit a28e3da

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/org/truffleruby/core/range/RangeNodes.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.core.range;
1111

12+
import com.oracle.truffle.api.profiles.LoopConditionProfile;
1213
import org.truffleruby.builtins.CoreMethod;
1314
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1415
import org.truffleruby.builtins.CoreMethodNode;
@@ -93,7 +94,8 @@ public abstract static class EachNode extends YieldingCoreMethodNode {
9394
@Child private DispatchNode eachInternalCall;
9495

9596
@Specialization
96-
protected RubyIntRange eachInt(RubyIntRange range, RubyProc block) {
97+
protected RubyIntRange eachInt(RubyIntRange range, RubyProc block,
98+
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
9799
int result;
98100
if (range.excludedEnd) {
99101
result = range.end;
@@ -104,7 +106,8 @@ protected RubyIntRange eachInt(RubyIntRange range, RubyProc block) {
104106

105107
int n = range.begin;
106108
try {
107-
for (; n < exclusiveEnd; n++) {
109+
loopProfile.profileCounted(exclusiveEnd - range.begin);
110+
for (; loopProfile.inject(n < exclusiveEnd); n++) {
108111
callBlock(block, n);
109112
}
110113
} finally {
@@ -115,7 +118,8 @@ protected RubyIntRange eachInt(RubyIntRange range, RubyProc block) {
115118
}
116119

117120
@Specialization
118-
protected RubyLongRange eachLong(RubyLongRange range, RubyProc block) {
121+
protected RubyLongRange eachLong(RubyLongRange range, RubyProc block,
122+
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
119123
long result;
120124
if (range.excludedEnd) {
121125
result = range.end;
@@ -126,7 +130,8 @@ protected RubyLongRange eachLong(RubyLongRange range, RubyProc block) {
126130

127131
long n = range.begin;
128132
try {
129-
for (; n < exclusiveEnd; n++) {
133+
loopProfile.profileCounted(exclusiveEnd - range.begin);
134+
for (; loopProfile.inject(n < exclusiveEnd); n++) {
130135
callBlock(block, n);
131136
}
132137
} finally {

0 commit comments

Comments
 (0)