MCPcopy Create free account
hub / github.com/apache/arrow / can_reuse_memory

Function can_reuse_memory

r/src/r_to_arrow.cpp:1216–1232  ·  view source on GitHub ↗

in some situations we can just use the memory of the R object in an RBuffer instead of going through ArrayBuilder, etc ...

Source from the content-addressed store, hash-verified

1214// in some situations we can just use the memory of the R object in an RBuffer
1215// instead of going through ArrayBuilder, etc ...
1216bool can_reuse_memory(SEXP x, const std::shared_ptr<arrow::DataType>& type) {
1217 // TODO: this probably should be disabled when x is an ALTREP object
1218 // because MakeSimpleArray below will force materialization
1219 switch (type->id()) {
1220 case Type::INT32:
1221 return TYPEOF(x) == INTSXP && !Rf_isObject(x);
1222 case Type::DOUBLE:
1223 return TYPEOF(x) == REALSXP && !Rf_isObject(x);
1224 case Type::INT8:
1225 return TYPEOF(x) == RAWSXP && !Rf_isObject(x);
1226 case Type::INT64:
1227 return TYPEOF(x) == REALSXP && Rf_inherits(x, "integer64");
1228 default:
1229 break;
1230 }
1231 return false;
1232}
1233
1234// this is only used on some special cases when the arrow Array can just use the memory of
1235// the R object, via an RBuffer, hence be zero copy

Callers 1

Calls 1

idMethod · 0.45

Tested by

no test coverage detected