Skip to content

Commit 55ce0b4

Browse files
committed
Simplify to a single specialization for NativeArraySetNode
1 parent 2080b0a commit 55ce0b4

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/main/java/org/truffleruby/core/array/NativeArrayNodes.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.oracle.truffle.api.interop.UnsupportedMessageException;
1818
import com.oracle.truffle.api.library.CachedLibrary;
1919

20+
import com.oracle.truffle.api.profiles.BranchProfile;
2021
import org.truffleruby.cext.WrapNode;
2122
import org.truffleruby.cext.UnwrapNode.UnwrapNativeNode;
2223
import org.truffleruby.core.array.NativeArrayNodesFactory.NativeArrayCapacityNodeGen;
@@ -58,27 +59,24 @@ public static NativeArrayGetNode create() {
5859

5960
public static abstract class NativeArraySetNode extends ArrayOperationNodes.ArraySetNode {
6061

61-
@Specialization(rewriteOn = UnsupportedMessageException.class)
62+
@Specialization
6263
protected void set(NativeArrayStorage storage, int index, Object object,
6364
@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;
7368
try {
74-
storage.writeElement(index, values.asPointer(wrapNode.execute(object)));
69+
value = values.asPointer(wrapNode.execute(object));
7570
} catch (UnsupportedMessageException e) {
71+
errorProfile.enter();
7672
throw new RaiseException(
7773
getContext(),
7874
getContext()
7975
.getCoreExceptions()
8076
.argumentError("Could not convert value for native storage", this));
8177
}
78+
79+
storage.writeElement(index, value);
8280
}
8381

8482
public static NativeArraySetNode create() {

0 commit comments

Comments
 (0)