Skip to content

Commit 105e7f9

Browse files
committed
Loop profile UnwrapCArrayNode
1 parent 7a50aae commit 105e7f9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/org/truffleruby/cext/UnwrapNode.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.oracle.truffle.api.dsl.Bind;
1818
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
1919
import com.oracle.truffle.api.nodes.ExplodeLoop;
20+
import com.oracle.truffle.api.nodes.LoopNode;
21+
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2022
import org.truffleruby.RubyContext;
2123
import org.truffleruby.RubyLanguage;
2224
import org.truffleruby.cext.UnwrapNodeGen.NativeToWrapperNodeGen;
@@ -219,24 +221,27 @@ protected Object[] unwrapCArrayExplode(Object cArray,
219221
protected Object[] unwrapCArray(Object cArray,
220222
@CachedLibrary("cArray") InteropLibrary interop,
221223
@Bind("getArraySize(cArray, interop)") int size,
222-
@Cached UnwrapNode unwrapNode) {
224+
@Cached UnwrapNode unwrapNode,
225+
@Cached LoopConditionProfile loopProfile) {
223226
final Object[] store = new Object[size];
224-
for (int i = 0; i < size; i++) {
227+
loopProfile.profileCounted(size);
228+
for (int i = 0; loopProfile.inject(i < size); i++) {
225229
final Object cValue = readArrayElement(cArray, interop, i);
226230
store[i] = unwrapNode.execute(cValue);
227231
}
232+
LoopNode.reportLoopCount(this, size);
228233
return store;
229234
}
230235

231-
protected int getArraySize(Object cArray, InteropLibrary interop) {
236+
protected static int getArraySize(Object cArray, InteropLibrary interop) {
232237
try {
233238
return Math.toIntExact(interop.getArraySize(cArray));
234239
} catch (UnsupportedMessageException | ArithmeticException e) {
235240
throw CompilerDirectives.shouldNotReachHere(e);
236241
}
237242
}
238243

239-
private Object readArrayElement(Object cArray, InteropLibrary interop, int i) {
244+
private static Object readArrayElement(Object cArray, InteropLibrary interop, int i) {
240245
try {
241246
return interop.readArrayElement(cArray, i);
242247
} catch (UnsupportedMessageException | InvalidArrayIndexException e) {

0 commit comments

Comments
 (0)