| 192 | } |
| 193 | |
| 194 | Result<std::shared_ptr<Buffer>> ConcatenateBuffers( |
| 195 | const std::vector<std::shared_ptr<Buffer>>& buffers, MemoryPool* pool) { |
| 196 | int64_t out_length = 0; |
| 197 | for (const auto& buffer : buffers) { |
| 198 | out_length += buffer->size(); |
| 199 | } |
| 200 | ARROW_ASSIGN_OR_RAISE(auto out, AllocateBuffer(out_length, pool)); |
| 201 | auto out_data = out->mutable_data(); |
| 202 | for (const auto& buffer : buffers) { |
| 203 | // Passing nullptr to std::memcpy is undefined behavior, so skip empty buffers |
| 204 | if (buffer->size() != 0) { |
| 205 | std::memcpy(out_data, buffer->data(), buffer->size()); |
| 206 | out_data += buffer->size(); |
| 207 | } |
| 208 | } |
| 209 | return out; |
| 210 | } |
| 211 | |
| 212 | } // namespace arrow |