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

Function can_reuse_memory

r/src/r_to_arrow.cpp:1209–1225  ·  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

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

Callers 1

Calls 1

idMethod · 0.45

Tested by

no test coverage detected