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

Change WiredTigerUtil::exportTableToBSON to use StringMap

    • Storage Execution
    • Fully Compatible
    • Execution Team 2024-01-08
    • 35

      WiredTigerUtil::exportTableToBSON uses std::map<string, BSONObjBuilder> which causes a lot of unnecessary temporary string allocations to lookup values.

      --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
      +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
      @@ -1120,7 +1121,7 @@ Status WiredTigerUtil::exportTableToBSON(WT_SESSION* session,
           invariant(c);
           ON_BLOCK_EXIT([&] { c->close(c); });
      
      -    std::map<string, BSONObjBuilder*> subs;
      +    StringMap<BSONObjBuilder*> subs;
           const char* desc;
           uint64_t value;
           while (c->next(c) == 0 && c->get_value(c, &desc, nullptr, &value) == 0) {
      @@ -1155,18 +1156,17 @@ Status WiredTigerUtil::exportTableToBSON(WT_SESSION* session,
                       continue;
                   }
      
      -            BSONObjBuilder*& sub = subs[prefix.toString()];
      +            BSONObjBuilder*& sub = subs[prefix];
                   if (!sub)
                       sub = new BSONObjBuilder();
      -            sub->appendNumber(str::ltrim(suffix.toString()), v);
      +            sub->appendNumber(str::ltrim(suffix), v);
               }
           }
      
      -    for (std::map<string, BSONObjBuilder*>::const_iterator it = subs.begin(); it != subs.end();
      -         ++it) {
      -        const std::string& s = it->first;
      -        bob->append(s, it->second->obj());
      -        delete it->second;
      +    for (const auto &kvp : subs ) {
      +        const std::string& s = kvp.first;
      +        bob->append(s, kvp.second->obj());
      +        // delete it->second;
           }
           return Status::OK();
       }
      

            Assignee:
            brad.cater@mongodb.com Brad Cater
            Reporter:
            mark.benvenuto@mongodb.com Mark Benvenuto
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: