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

Method Dataptr

r/src/altrep.cpp:240–261  ·  view source on GitHub ↗

R calls this to get a pointer to the start of the data, R allocations are allowed.

Source from the content-addressed store, hash-verified

238
239 // R calls this to get a pointer to the start of the data, R allocations are allowed.
240 static void* Dataptr(SEXP alt, Rboolean writeable) {
241 // If the object hasn't been materialized, and the array has no
242 // nulls we can directly point to the array data.
243 if (!IsMaterialized(alt)) {
244 const auto& chunked_array = GetChunkedArray(alt);
245
246 if (chunked_array->num_chunks() == 1 && chunked_array->null_count() == 0) {
247 return reinterpret_cast<void*>(const_cast<c_type*>(
248 chunked_array->chunk(0)->data()->template GetValues<c_type>(1)));
249 }
250 }
251
252 // Otherwise we have to materialize and hand the pointer to data2
253 if constexpr (std::is_same_v<c_type, double>) {
254 return REAL(Materialize(alt));
255 } else if constexpr (std::is_same_v<c_type, int>) {
256 return INTEGER(Materialize(alt));
257 } else {
258 static_assert(std::is_same_v<c_type, double> || std::is_same_v<c_type, int>,
259 "ALTREP not implemented for this c_type");
260 }
261 }
262
263 // The value at position i
264 static c_type Elt(SEXP alt, R_xlen_t i) {

Callers

nothing calls this directly

Calls 4

MaterializeFunction · 0.50
num_chunksMethod · 0.45
null_countMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected