Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-83722

IDL Parser should copy a vector directly when parsing a DocumentSequence if the final vector is also std::vector<BSONObj>

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 8.0.0-rc5
    • Affects Version/s: None
    • Component/s: None
    • Service Arch
    • Fully Compatible
    • v8.0
    • Service Arch 2024-04-01, Service Arch 2024-04-15, Service Arch 2024-04-29, Service Arch 2024-05-13

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

            Assignee:
            dominic.hernandez@mongodb.com Dominic Hernandez
            Reporter:
            vishnu.kaushik@mongodb.com Vishnu Kaushik
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: