MCPcopy Create free account
hub / github.com/apache/arrow / operator()

Method operator()

cpp/src/arrow/io/memory_test.cc:458–477  ·  view source on GitHub ↗

A transform that swaps every pair of bytes

Source from the content-addressed store, hash-verified

456struct SwappingTransform {
457 // A transform that swaps every pair of bytes
458 Result<std::shared_ptr<Buffer>> operator()(const std::shared_ptr<Buffer>& buf) {
459 int64_t dest_size = bit_util::RoundDown(buf->size() + has_pending_, 2);
460 ARROW_ASSIGN_OR_RAISE(auto dest, AllocateBuffer(dest_size));
461 const uint8_t* data = buf->data();
462 uint8_t* out_data = dest->mutable_data();
463 if (has_pending_ && dest_size > 0) {
464 *out_data++ = *data++;
465 *out_data++ = pending_byte_;
466 dest_size -= 2;
467 }
468 for (int64_t i = 0; i < dest_size; i += 2) {
469 out_data[i] = data[i + 1];
470 out_data[i + 1] = data[i];
471 }
472 has_pending_ = has_pending_ ^ (buf->size() & 1);
473 if (has_pending_) {
474 pending_byte_ = buf->data()[buf->size() - 1];
475 }
476 return std::shared_ptr<Buffer>(std::move(dest));
477 }
478
479 protected:
480 bool has_pending_ = 0;

Callers

nothing calls this directly

Calls 4

RoundDownFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected