|
17 | 17 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
18 | 18 | import com.oracle.truffle.api.library.CachedLibrary;
|
19 | 19 |
|
| 20 | +import com.oracle.truffle.api.profiles.BranchProfile; |
20 | 21 | import org.truffleruby.cext.WrapNode;
|
21 | 22 | import org.truffleruby.cext.UnwrapNode.UnwrapNativeNode;
|
22 | 23 | import org.truffleruby.core.array.NativeArrayNodesFactory.NativeArrayCapacityNodeGen;
|
@@ -58,27 +59,24 @@ public static NativeArrayGetNode create() {
|
58 | 59 |
|
59 | 60 | public static abstract class NativeArraySetNode extends ArrayOperationNodes.ArraySetNode {
|
60 | 61 |
|
61 |
| - @Specialization(rewriteOn = UnsupportedMessageException.class) |
| 62 | + @Specialization |
62 | 63 | protected void set(NativeArrayStorage storage, int index, Object object,
|
63 | 64 | @Cached WrapNode wrapNode,
|
64 |
| - @CachedLibrary(limit = "1") InteropLibrary values) throws UnsupportedMessageException { |
65 |
| - long value = values.asPointer(wrapNode.execute(object)); |
66 |
| - storage.writeElement(index, value); |
67 |
| - } |
68 |
| - |
69 |
| - @Specialization(replaces = "set") |
70 |
| - protected void setGeneric(NativeArrayStorage storage, int index, Object object, |
71 |
| - @Cached WrapNode wrapNode, |
72 |
| - @CachedLibrary(limit = "1") InteropLibrary values) { |
| 65 | + @CachedLibrary(limit = "1") InteropLibrary values, |
| 66 | + @Cached BranchProfile errorProfile) { |
| 67 | + long value; |
73 | 68 | try {
|
74 |
| - storage.writeElement(index, values.asPointer(wrapNode.execute(object))); |
| 69 | + value = values.asPointer(wrapNode.execute(object)); |
75 | 70 | } catch (UnsupportedMessageException e) {
|
| 71 | + errorProfile.enter(); |
76 | 72 | throw new RaiseException(
|
77 | 73 | getContext(),
|
78 | 74 | getContext()
|
79 | 75 | .getCoreExceptions()
|
80 | 76 | .argumentError("Could not convert value for native storage", this));
|
81 | 77 | }
|
| 78 | + |
| 79 | + storage.writeElement(index, value); |
82 | 80 | }
|
83 | 81 |
|
84 | 82 | public static NativeArraySetNode create() {
|
|
0 commit comments