9
9
*/
10
10
package org .truffleruby .core .range ;
11
11
12
+ import com .oracle .truffle .api .profiles .LoopConditionProfile ;
12
13
import org .truffleruby .builtins .CoreMethod ;
13
14
import org .truffleruby .builtins .CoreMethodArrayArgumentsNode ;
14
15
import org .truffleruby .builtins .CoreMethodNode ;
@@ -93,7 +94,8 @@ public abstract static class EachNode extends YieldingCoreMethodNode {
93
94
@ Child private DispatchNode eachInternalCall ;
94
95
95
96
@ Specialization
96
- protected RubyIntRange eachInt (RubyIntRange range , RubyProc block ) {
97
+ protected RubyIntRange eachInt (RubyIntRange range , RubyProc block ,
98
+ @ Cached ("createCountingProfile()" ) LoopConditionProfile loopProfile ) {
97
99
int result ;
98
100
if (range .excludedEnd ) {
99
101
result = range .end ;
@@ -104,7 +106,8 @@ protected RubyIntRange eachInt(RubyIntRange range, RubyProc block) {
104
106
105
107
int n = range .begin ;
106
108
try {
107
- for (; n < exclusiveEnd ; n ++) {
109
+ loopProfile .profileCounted (exclusiveEnd - range .begin );
110
+ for (; loopProfile .inject (n < exclusiveEnd ); n ++) {
108
111
callBlock (block , n );
109
112
}
110
113
} finally {
@@ -115,7 +118,8 @@ protected RubyIntRange eachInt(RubyIntRange range, RubyProc block) {
115
118
}
116
119
117
120
@ Specialization
118
- protected RubyLongRange eachLong (RubyLongRange range , RubyProc block ) {
121
+ protected RubyLongRange eachLong (RubyLongRange range , RubyProc block ,
122
+ @ Cached ("createCountingProfile()" ) LoopConditionProfile loopProfile ) {
119
123
long result ;
120
124
if (range .excludedEnd ) {
121
125
result = range .end ;
@@ -126,7 +130,8 @@ protected RubyLongRange eachLong(RubyLongRange range, RubyProc block) {
126
130
127
131
long n = range .begin ;
128
132
try {
129
- for (; n < exclusiveEnd ; n ++) {
133
+ loopProfile .profileCounted (exclusiveEnd - range .begin );
134
+ for (; loopProfile .inject (n < exclusiveEnd ); n ++) {
130
135
callBlock (block , n );
131
136
}
132
137
} finally {
0 commit comments