From 48eac29317c2d4ea54ffc14f1a83cc6ba3e55645 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 28 Feb 2024 11:56:24 +0100 Subject: [PATCH] Avoid unnecessary unique_ptr indirection --- cpp/src/arrow/c/bridge.cc | 13 +++++++------ cpp/src/arrow/gpu/cuda_test.cc | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cpp/src/arrow/c/bridge.cc b/cpp/src/arrow/c/bridge.cc index d32ce6051ed52..0ffa5291812a9 100644 --- a/cpp/src/arrow/c/bridge.cc +++ b/cpp/src/arrow/c/bridge.cc @@ -567,6 +567,7 @@ void ReleaseExportedArray(struct ArrowArray* array) { struct ArrayExporter { explicit ArrayExporter(bool device_interface = false) : device_interface_(device_interface) {} + Status Export(const std::shared_ptr& data) { // Force computing null count. // This is because ARROW-9037 is in version 0.17 and 0.17.1, and they are @@ -614,10 +615,10 @@ struct ArrayExporter { // Export children export_.children_.resize(data->child_data.size()); - child_exporters_.resize(data->child_data.size()); - for (size_t i = 0; i < data->child_data.size(); ++i) { - child_exporters_[i] = std::make_unique(device_interface_); - RETURN_NOT_OK(child_exporters_[i]->Export(data->child_data[i])); + child_exporters_.reserve(data->child_data.size()); + for (const auto& child : data->child_data) { + child_exporters_.emplace_back(ArrayExporter{device_interface_}); + RETURN_NOT_OK(child_exporters_.back().Export(child)); } // Store owning pointer to ArrayData @@ -647,7 +648,7 @@ struct ArrayExporter { for (size_t i = 0; i < data.child_data.size(); ++i) { auto ptr = &pdata->children_[i]; pdata->child_pointers_[i] = ptr; - child_exporters_[i]->Finish(ptr); + child_exporters_[i].Finish(ptr); } // Third, fill C struct. @@ -668,7 +669,7 @@ struct ArrayExporter { ExportedArrayPrivateData export_; std::unique_ptr dict_exporter_; - std::vector> child_exporters_; + std::vector child_exporters_; bool device_interface_ = false; }; diff --git a/cpp/src/arrow/gpu/cuda_test.cc b/cpp/src/arrow/gpu/cuda_test.cc index e6001445de00d..d2f01cb3bbc0c 100644 --- a/cpp/src/arrow/gpu/cuda_test.cc +++ b/cpp/src/arrow/gpu/cuda_test.cc @@ -767,6 +767,7 @@ class TestCudaDeviceArrayRoundtrip : public ::testing::Test { std::shared_ptr array_roundtripped; ASSERT_OK_AND_ASSIGN(array_roundtripped, device_array_roundtripped->CopyTo(default_cpu_memory_manager())); + ASSERT_OK(array_roundtripped->ValidateFull()); { std::shared_ptr expected; ASSERT_OK_AND_ASSIGN(expected, factory_expected()); @@ -786,6 +787,7 @@ class TestCudaDeviceArrayRoundtrip : public ::testing::Test { array_roundtripped.reset(); ASSERT_OK_AND_ASSIGN(array_roundtripped, device_array_roundtripped->CopyTo(default_cpu_memory_manager())); + ASSERT_OK(array_roundtripped->ValidateFull()); { std::shared_ptr expected; ASSERT_OK_AND_ASSIGN(expected, factory_expected());