Skip to content

Commit b563f23

Browse files
committed
[GR-22670] Rewrite ConvertBooleanNode to use VectorDataLibrary
(cherry picked from commit 422a97d)
1 parent 2959340 commit b563f23

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/ConvertBooleanNode.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
import com.oracle.truffle.r.runtime.data.RRaw;
4242
import com.oracle.truffle.r.runtime.data.VectorDataLibrary;
4343
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
44-
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess;
45-
import com.oracle.truffle.r.runtime.data.nodes.VectorAccess.SequentialIterator;
4644
import com.oracle.truffle.r.runtime.interop.ConvertForeignObjectNode;
4745
import com.oracle.truffle.r.runtime.nodes.RNode;
4846
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
@@ -116,10 +114,10 @@ protected byte doString(String value) {
116114
return logicalValue;
117115
}
118116

119-
@Specialization(guards = "value.getLength() == 1", limit = "getGenericVectorAccessCacheSize()")
117+
@Specialization(guards = "library.getLength(value.getData()) == 1", limit = "getTypedVectorDataLibraryCacheSize()")
120118
protected byte doRLogical(RLogicalVector value,
121119
@CachedLibrary("value.getData()") VectorDataLibrary library) {
122-
// fast path for very common case, handled also in doAtomicVector
120+
// fast path for very common case, handled also in doVector
123121
byte res = library.getLogicalAt(value.getData(), 0);
124122
if (naProfile.isNA(res)) {
125123
throw error(RError.Message.NA_UNEXP);
@@ -143,35 +141,29 @@ private void checkLength(int length) {
143141
}
144142
}
145143

146-
@Specialization(guards = "access.supports(value)", limit = "getCacheSize(ATOMIC_VECTOR_LIMIT)")
144+
@Specialization(replaces = "doRLogical", limit = "getGenericDataLibraryCacheSize()")
147145
protected byte doVector(RAbstractVector value,
148-
@Cached("value.access()") VectorAccess access) {
149-
SequentialIterator it = access.access(value);
150-
checkLength(access.getLength(it));
151-
access.next(it);
152-
switch (access.getType()) {
146+
@CachedLibrary("value.getData()") VectorDataLibrary dataLib) {
147+
Object data = value.getData();
148+
checkLength(dataLib.getLength(data));
149+
switch (dataLib.getType(data)) {
153150
case Integer:
154-
return doInt(access.getInt(it));
151+
return doInt(dataLib.getIntAt(data, 0));
155152
case Double:
156-
return doDouble(access.getDouble(it));
153+
return doDouble(dataLib.getDoubleAt(data, 0));
157154
case Raw:
158-
return RRuntime.raw2logical(access.getRaw(it));
155+
return RRuntime.raw2logical(dataLib.getRawAt(data, 0));
159156
case Logical:
160-
return doLogical(access.getLogical(it));
157+
return doLogical(dataLib.getLogicalAt(data, 0));
161158
case Character:
162-
return doString(access.getString(it));
159+
return doString(dataLib.getStringAt(data, 0));
163160
case Complex:
164-
return doComplex(access.getComplex(it));
161+
return doComplex(dataLib.getComplexAt(data, 0));
165162
default:
166163
throw error(RError.Message.ARGUMENT_NOT_INTERPRETABLE_LOGICAL);
167164
}
168165
}
169166

170-
@Specialization(replaces = "doVector")
171-
protected byte doVectorGeneric(RAbstractVector value) {
172-
return doVector(value, value.slowPathAccess());
173-
}
174-
175167
@Specialization(guards = "isForeignObject(obj)")
176168
protected byte doForeignObject(VirtualFrame frame, TruffleObject obj,
177169
@Cached("create()") ConvertForeignObjectNode convertForeign) {

0 commit comments

Comments
 (0)