| 150 | namespace { |
| 151 | template <typename Fn> |
| 152 | Result<std::shared_ptr<ArrayData>> CopyToImpl(const ArrayData& data, |
| 153 | const std::shared_ptr<MemoryManager>& to, |
| 154 | Fn&& copy_fn) { |
| 155 | auto output = ArrayData::Make(data.type, data.length, data.null_count, data.offset); |
| 156 | output->buffers.resize(data.buffers.size()); |
| 157 | for (auto&& [buf, out_buf] : internal::Zip(data.buffers, output->buffers)) { |
| 158 | if (buf) { |
| 159 | ARROW_ASSIGN_OR_RAISE(out_buf, copy_fn(buf, to)); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | output->child_data.reserve(data.child_data.size()); |
| 164 | for (const auto& child : data.child_data) { |
| 165 | ARROW_ASSIGN_OR_RAISE(auto copied, CopyToImpl(*child, to, copy_fn)); |
| 166 | output->child_data.push_back(std::move(copied)); |
| 167 | } |
| 168 | |
| 169 | if (data.dictionary) { |
| 170 | ARROW_ASSIGN_OR_RAISE(output->dictionary, CopyToImpl(*data.dictionary, to, copy_fn)); |
| 171 | } |
| 172 | |
| 173 | output->statistics = data.statistics; |
| 174 | |
| 175 | return output; |
| 176 | } |
| 177 | } // namespace |
| 178 | |
| 179 | Result<std::shared_ptr<ArrayData>> ArrayData::CopyTo( |