|
17 | 17 | import com.oracle.truffle.api.dsl.Bind;
|
18 | 18 | import com.oracle.truffle.api.interop.InvalidArrayIndexException;
|
19 | 19 | import com.oracle.truffle.api.nodes.ExplodeLoop;
|
| 20 | +import com.oracle.truffle.api.nodes.LoopNode; |
| 21 | +import com.oracle.truffle.api.profiles.LoopConditionProfile; |
20 | 22 | import org.truffleruby.RubyContext;
|
21 | 23 | import org.truffleruby.RubyLanguage;
|
22 | 24 | import org.truffleruby.cext.UnwrapNodeGen.NativeToWrapperNodeGen;
|
@@ -219,24 +221,27 @@ protected Object[] unwrapCArrayExplode(Object cArray,
|
219 | 221 | protected Object[] unwrapCArray(Object cArray,
|
220 | 222 | @CachedLibrary("cArray") InteropLibrary interop,
|
221 | 223 | @Bind("getArraySize(cArray, interop)") int size,
|
222 |
| - @Cached UnwrapNode unwrapNode) { |
| 224 | + @Cached UnwrapNode unwrapNode, |
| 225 | + @Cached LoopConditionProfile loopProfile) { |
223 | 226 | 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++) { |
225 | 229 | final Object cValue = readArrayElement(cArray, interop, i);
|
226 | 230 | store[i] = unwrapNode.execute(cValue);
|
227 | 231 | }
|
| 232 | + LoopNode.reportLoopCount(this, size); |
228 | 233 | return store;
|
229 | 234 | }
|
230 | 235 |
|
231 |
| - protected int getArraySize(Object cArray, InteropLibrary interop) { |
| 236 | + protected static int getArraySize(Object cArray, InteropLibrary interop) { |
232 | 237 | try {
|
233 | 238 | return Math.toIntExact(interop.getArraySize(cArray));
|
234 | 239 | } catch (UnsupportedMessageException | ArithmeticException e) {
|
235 | 240 | throw CompilerDirectives.shouldNotReachHere(e);
|
236 | 241 | }
|
237 | 242 | }
|
238 | 243 |
|
239 |
| - private Object readArrayElement(Object cArray, InteropLibrary interop, int i) { |
| 244 | + private static Object readArrayElement(Object cArray, InteropLibrary interop, int i) { |
240 | 245 | try {
|
241 | 246 | return interop.readArrayElement(cArray, i);
|
242 | 247 | } catch (UnsupportedMessageException | InvalidArrayIndexException e) {
|
|
0 commit comments