Skip to content

Commit

Permalink
apacheGH-36342: [C++] Add missing move semantic to RecordBatch
Browse files Browse the repository at this point in the history
In file record_batch.cc there are some places that using move semantic
can avoid coping vector or increasing reference count of shared_ptr.

Signed-off-by: Zhao Junwang <zhjwpku@gmail.com>
  • Loading branch information
zhjwpku committed Jun 28, 2023
1 parent 0344a2c commit 03b8319
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cpp/src/arrow/record_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ std::shared_ptr<RecordBatch> RecordBatch::Make(
std::shared_ptr<Schema> schema, int64_t num_rows,
std::vector<std::shared_ptr<Array>> columns) {
DCHECK_EQ(schema->num_fields(), static_cast<int>(columns.size()));
return std::make_shared<SimpleRecordBatch>(std::move(schema), num_rows, columns);
return std::make_shared<SimpleRecordBatch>(std::move(schema), num_rows,
std::move(columns));
}

std::shared_ptr<RecordBatch> RecordBatch::Make(
Expand All @@ -194,7 +195,7 @@ Result<std::shared_ptr<RecordBatch>> RecordBatch::MakeEmpty(
ARROW_ASSIGN_OR_RAISE(empty_batch[i],
MakeEmptyArray(schema->field(i)->type(), memory_pool));
}
return RecordBatch::Make(schema, 0, empty_batch);
return RecordBatch::Make(std::move(schema), 0, std::move(empty_batch));
}

Result<std::shared_ptr<RecordBatch>> RecordBatch::FromStructArray(
Expand Down Expand Up @@ -391,7 +392,7 @@ Result<std::shared_ptr<RecordBatchReader>> RecordBatchReader::Make(
schema = batches[0]->schema();
}

return std::make_shared<SimpleRecordBatchReader>(std::move(batches), schema);
return std::make_shared<SimpleRecordBatchReader>(std::move(batches), std::move(schema));
}

Result<std::shared_ptr<RecordBatchReader>> RecordBatchReader::MakeFromIterator(
Expand All @@ -400,7 +401,7 @@ Result<std::shared_ptr<RecordBatchReader>> RecordBatchReader::MakeFromIterator(
return Status::Invalid("Schema cannot be nullptr");
}

return std::make_shared<SimpleRecordBatchReader>(std::move(batches), schema);
return std::make_shared<SimpleRecordBatchReader>(std::move(batches), std::move(schema));
}

RecordBatchReader::~RecordBatchReader() {
Expand Down

0 comments on commit 03b8319

Please sign in to comment.