[SERVER-83722] IDL Parser should copy a vector directly when parsing a DocumentSequence if the final vector is also std::vector<BSONObj> Created: 29/Nov/23  Updated: 19/Dec/23

Status: Open
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Vishnu Kaushik Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: perf
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Sprint: Service Arch Prioritized List
Participants:

 Description   

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;.


Generated at Thu Feb 08 06:52:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.