Below is the generated code (write_ops_gen.cpp, from write_ops.idl) to parse a DocumentSequence of documents for the insert command.
if (sequence.name == kDocumentsFieldName) { if (MONGO_unlikely(usedFields[kDocumentsBit])) { ctxt.throwDuplicateField(sequence.name); } usedFields.set(kDocumentsBit); _hasMembers.markPresent(static_cast<size_t>(RequiredFields::documents)); std::vector<mongo::BSONObj> values; for (const BSONObj& sequenceObject : sequence.objs) { values.emplace_back(sequenceObject); } _documents = std::move(values); }
Since the result vector of _documents is already of type std::vector<BsonObj>, rather than iterating through each BSONObj in sequence.objs and copy constructing it into a vector values, and then finally move-assigning it to _documents, we can just directly have a single line of code _documents = sequence.objs;.