Skip to content

Commit 0513002

Browse files
authored
GH-37891: [C++] Followup SliceBuffer shared_ptr move usage (#45941)
### Rationale for this change #45466 Has basic implement the `SliceBuffer` api. This pr is a followup ### What changes are included in this PR? Change the `SliceBuffer` buffer usage ### Are these changes tested? Covered by existing ### Are there any user-facing changes? no * GitHub Issue: #37891 Authored-by: mwish <[email protected]> Signed-off-by: mwish <[email protected]>
1 parent b4ba60a commit 0513002

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

cpp/src/arrow/compute/row/grouper.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -812,14 +812,14 @@ struct GrouperFastImpl : public Grouper {
812812
ARROW_ASSIGN_OR_RAISE(
813813
std::shared_ptr<Buffer> buf,
814814
AllocateBitmap(length + kBitmapPaddingForSIMD, ctx_->memory_pool()));
815-
return SliceMutableBuffer(buf, 0, bit_util::BytesForBits(length));
815+
return SliceMutableBuffer(std::move(buf), 0, bit_util::BytesForBits(length));
816816
}
817817

818818
Result<std::shared_ptr<Buffer>> AllocatePaddedBuffer(int64_t size) {
819819
ARROW_ASSIGN_OR_RAISE(
820820
std::shared_ptr<Buffer> buf,
821821
AllocateBuffer(size + kBitmapPaddingForSIMD, ctx_->memory_pool()));
822-
return SliceMutableBuffer(buf, 0, size);
822+
return SliceMutableBuffer(std::move(buf), 0, size);
823823
}
824824

825825
Result<ExecBatch> GetUniques() override {

cpp/src/arrow/csv/reader.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ class CSVBufferIterator {
126126
}
127127

128128
trailing_cr_ = (buf->data()[buf->size() - 1] == '\r');
129-
buf = SliceBuffer(buf, offset);
129+
buf = SliceBuffer(std::move(buf), offset);
130130
if (buf->size() == 0) {
131131
// EOF
132132
return TransformFinish();
133133
} else {
134-
return TransformYield(buf);
134+
return TransformYield(std::move(buf));
135135
}
136136
}
137137

cpp/src/arrow/io/transform.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ Result<int64_t> TransformInputStream::Read(int64_t nbytes, void* out) {
125125
}
126126
{
127127
// Last buffer: splice into `out` and `pending_`
128-
const auto buf = std::move(avail.back());
128+
auto buf = std::move(avail.back());
129129
const int64_t to_copy = std::min(buf->size(), nbytes);
130130
memcpy(out_data, buf->data(), static_cast<size_t>(to_copy));
131131
copied_bytes += to_copy;
132132
if (buf->size() > to_copy) {
133-
impl_->pending_ = SliceBuffer(buf, to_copy);
133+
impl_->pending_ = SliceBuffer(std::move(buf), to_copy);
134134
} else {
135135
impl_->pending_.reset();
136136
}

cpp/src/arrow/ipc/writer.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ class RecordBatchSerializer {
444444
const int64_t buffer_length =
445445
std::min(bit_util::RoundUpToMultipleOf8(array.length() * type_width),
446446
data->size() - byte_offset);
447-
data = SliceBuffer(data, byte_offset, buffer_length);
447+
data = SliceBuffer(std::move(data), byte_offset, buffer_length);
448448
}
449449
out_->body_buffers.emplace_back(std::move(data));
450450
return Status::OK();
@@ -473,7 +473,7 @@ class RecordBatchSerializer {
473473
const int64_t start_offset = array.value_offset(0);
474474
const int64_t slice_length =
475475
std::min(PaddedLength(total_data_bytes), data->size() - start_offset);
476-
data = SliceBuffer(data, start_offset, slice_length);
476+
data = SliceBuffer(std::move(data), start_offset, slice_length);
477477
}
478478

479479
out_->body_buffers.emplace_back(std::move(value_offsets));

cpp/src/arrow/util/delimiting.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ Status Chunker::ProcessFinal(std::shared_ptr<Buffer> partial,
160160
if (first_pos == BoundaryFinder::kNoDelimiterFound) {
161161
// No delimiter in block => it's entirely a completion of partial
162162
*completion = block;
163-
*rest = SliceBuffer(block, 0, 0);
163+
*rest = SliceBuffer(std::move(block), 0, 0);
164164
} else {
165165
*completion = SliceBuffer(block, 0, first_pos);
166-
*rest = SliceBuffer(block, first_pos);
166+
*rest = SliceBuffer(std::move(block), first_pos);
167167
}
168168
return Status::OK();
169169
}
@@ -182,9 +182,9 @@ Status Chunker::ProcessSkip(std::shared_ptr<Buffer> partial,
182182
if (ARROW_PREDICT_FALSE(final && *count > num_found && block->size() != pos)) {
183183
// Skip the last row in the final block which does not have a delimiter
184184
++num_found;
185-
*rest = SliceBuffer(block, 0, 0);
185+
*rest = SliceBuffer(std::move(block), 0, 0);
186186
} else {
187-
*rest = SliceBuffer(block, pos);
187+
*rest = SliceBuffer(std::move(block), pos);
188188
}
189189
*count -= num_found;
190190
return Status::OK();

cpp/src/parquet/encoder.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ std::shared_ptr<Buffer> DeltaBitPackEncoder<DType>::FlushValues() {
11931193
PARQUET_THROW_NOT_OK(sink_.Advance(kMaxPageHeaderWriterSize));
11941194

11951195
// Excess bytes at the beginning are sliced off and ignored.
1196-
return SliceBuffer(buffer, offset_bytes);
1196+
return SliceBuffer(std::move(buffer), offset_bytes);
11971197
}
11981198

11991199
template <>

0 commit comments

Comments
 (0)