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