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>

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • Service Arch
    • Service Arch Prioritized List

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

      Attachments

        Activity

          People

            backlog-server-servicearch Backlog - Service Architecture
            vishnu.kaushik@mongodb.com Vishnu Kaushik
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: