diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2021-04-06 13:29:26 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-08 13:53:23 +0000 |
commit | 0d88d02dbec6d3e83060e55211b7ce821df3d9d5 (patch) | |
tree | 3e665ad9488b81e5ebf4f54bf9eed51dda617571 /src/mongo/bson/bsonobj.h | |
parent | 3de090ad0ab2c587a198f1519642a3949d6a4a39 (diff) | |
download | mongo-0d88d02dbec6d3e83060e55211b7ce821df3d9d5.tar.gz |
SERVER-55835 Reuse calculated field name and value sizes in BSONIteratorSorted
Diffstat (limited to 'src/mongo/bson/bsonobj.h')
-rw-r--r-- | src/mongo/bson/bsonobj.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h index 9dee852bcba..cf168312940 100644 --- a/src/mongo/bson/bsonobj.h +++ b/src/mongo/bson/bsonobj.h @@ -857,8 +857,14 @@ public: BSONElement next() { verify(_fields); - if (_cur < _nfields) - return BSONElement(_fields[_cur++]); + if (_cur < _nfields) { + const auto& element = _fields[_cur++]; + return BSONElement(element.fieldName.rawData() - 1, // Include type byte + element.fieldName.size() + 1, // Add null terminator + element.totalSize, + BSONElement::CachedSizeTag{}); + } + return BSONElement(); } @@ -868,7 +874,11 @@ protected: private: const int _nfields; - const std::unique_ptr<const char*[]> _fields; + struct Field { + StringData fieldName; + int totalSize; + }; + const std::unique_ptr<Field[]> _fields; int _cur; }; |