Skip to content

Commit

Permalink
Avoid unnecessary unique_ptr indirection
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Feb 28, 2024
1 parent a38e318 commit 48eac29
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 7 additions & 6 deletions cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayData>& data) {
// Force computing null count.
// This is because ARROW-9037 is in version 0.17 and 0.17.1, and they are
Expand Down Expand Up @@ -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<ArrayExporter>(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
Expand Down Expand Up @@ -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.
Expand All @@ -668,7 +669,7 @@ struct ArrayExporter {

ExportedArrayPrivateData export_;
std::unique_ptr<ArrayExporter> dict_exporter_;
std::vector<std::unique_ptr<ArrayExporter>> child_exporters_;
std::vector<ArrayExporter> child_exporters_;
bool device_interface_ = false;
};

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/gpu/cuda_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ class TestCudaDeviceArrayRoundtrip : public ::testing::Test {
std::shared_ptr<Array> array_roundtripped;
ASSERT_OK_AND_ASSIGN(array_roundtripped,
device_array_roundtripped->CopyTo(default_cpu_memory_manager()));
ASSERT_OK(array_roundtripped->ValidateFull());
{
std::shared_ptr<Array> expected;
ASSERT_OK_AND_ASSIGN(expected, factory_expected());
Expand All @@ -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<Array> expected;
ASSERT_OK_AND_ASSIGN(expected, factory_expected());
Expand Down

0 comments on commit 48eac29

Please sign in to comment.