Skip to content

Commit a92d1ac

Browse files
committed
Avoid unnecessary copies
1 parent 4cc1ce1 commit a92d1ac

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/iceberg/update/update_schema.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ApplyChangesVisitor {
105105
auto moves_it = moves_.find(parent_id);
106106
if (moves_it != moves_.end() && !moves_it->second.empty()) {
107107
has_changes = true;
108-
new_fields = MoveFields(new_fields, moves_it->second);
108+
new_fields = MoveFields(std::move(new_fields), moves_it->second);
109109
}
110110

111111
if (!has_changes) {
@@ -217,8 +217,7 @@ class ApplyChangesVisitor {
217217

218218
/// \brief Helper function to apply move operations to a list of fields
219219
static std::vector<SchemaField> MoveFields(
220-
const std::vector<SchemaField>& fields,
221-
const std::vector<UpdateSchema::Move>& moves);
220+
std::vector<SchemaField>&& fields, const std::vector<UpdateSchema::Move>& moves);
222221

223222
const std::unordered_set<int32_t>& deletes_;
224223
const std::unordered_map<int32_t, std::shared_ptr<SchemaField>>& updates_;
@@ -227,9 +226,8 @@ class ApplyChangesVisitor {
227226
};
228227

229228
std::vector<SchemaField> ApplyChangesVisitor::MoveFields(
230-
const std::vector<SchemaField>& fields,
231-
const std::vector<UpdateSchema::Move>& moves) {
232-
std::vector<SchemaField> reordered = fields;
229+
std::vector<SchemaField>&& fields, const std::vector<UpdateSchema::Move>& moves) {
230+
std::vector<SchemaField> reordered = std::move(fields);
233231

234232
for (const auto& move : moves) {
235233
auto it = std::ranges::find_if(reordered, [&move](const SchemaField& field) {
@@ -748,7 +746,6 @@ UpdateSchema& UpdateSchema::MoveInternal(std::string_view name, const Move& move
748746
auto parent_it = id_to_parent_.find(move.field_id);
749747

750748
if (parent_it != id_to_parent_.end()) {
751-
// Field has a parent (nested field)
752749
int32_t parent_id = parent_it->second;
753750
auto parent_field_result = schema_->FindFieldById(parent_id);
754751

0 commit comments

Comments
 (0)