| 201 | } |
| 202 | |
| 203 | Result<std::shared_ptr<Buffer>> ConcatenateBuffers( |
| 204 | const std::vector<std::shared_ptr<Buffer>>& buffers, MemoryPool* pool) { |
| 205 | int64_t out_length = 0; |
| 206 | for (const auto& buffer : buffers) { |
| 207 | out_length += buffer->size(); |
| 208 | } |
| 209 | ARROW_ASSIGN_OR_RAISE(auto out, AllocateBuffer(out_length, pool)); |
| 210 | auto out_data = out->mutable_data(); |
| 211 | for (const auto& buffer : buffers) { |
| 212 | // Passing nullptr to std::memcpy is undefined behavior, so skip empty buffers |
| 213 | if (buffer->size() != 0) { |
| 214 | std::memcpy(out_data, buffer->data(), buffer->size()); |
| 215 | out_data += buffer->size(); |
| 216 | } |
| 217 | } |
| 218 | return out; |
| 219 | } |
| 220 | |
| 221 | } // namespace arrow |