diff options
Diffstat (limited to 'src/mongo/db/field_ref.h')
-rw-r--r-- | src/mongo/db/field_ref.h | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/mongo/db/field_ref.h b/src/mongo/db/field_ref.h index c1a50aaa969..39c985ec623 100644 --- a/src/mongo/db/field_ref.h +++ b/src/mongo/db/field_ref.h @@ -37,6 +37,7 @@ #include "mongo/base/disallow_copying.h" #include "mongo/base/string_data.h" +#include "mongo/util/container_size_helper.h" namespace mongo { @@ -59,8 +60,8 @@ public: explicit FieldRef(StringData path); /** - * Field parts accessed through getPart() calls no longer would be valid, after the - * destructor ran. + * Field parts accessed through getPart() calls no longer would be valid, after the destructor + * ran. */ ~FieldRef() {} @@ -70,8 +71,8 @@ public: void parse(StringData dottedField); /** - * Sets the 'i-th' field part to point to 'part'. Assumes i < size(). Behavior is - * undefined otherwise. + * Sets the 'i-th' field part to point to 'part'. Assumes i < size(). Behavior is undefined + * otherwise. */ void setPart(size_t i, StringData part); @@ -81,8 +82,8 @@ public: void appendPart(StringData part); /** - * Removes the last part from the path, decreasing its size by 1. Has no effect on a - * FieldRef with size 0. + * Removes the last part from the path, decreasing its size by 1. Has no effect on a FieldRef + * with size 0. */ void removeLastPart(); @@ -109,8 +110,8 @@ public: StringData dottedField(size_t offsetFromStart = 0) const; /** - * Returns a StringData of parts of the dotted field from startPart to endPart in its - * current state (i.e., some parts may have been replaced since the parse() call). + * Returns a StringData of parts of the dotted field from startPart to endPart in its current + * state (i.e., some parts may have been replaced since the parse() call). */ StringData dottedSubstring(size_t startPart, size_t endPart) const; @@ -120,8 +121,8 @@ public: bool equalsDottedField(StringData other) const; /** - * Return 0 if 'this' is equal to 'other' lexicographically, -1 if is it less than or - * +1 if it is greater than. + * Return 0 if 'this' is equal to 'other' lexicographically, -1 if is it less than or +1 if it + * is greater than. */ int compare(const FieldRef& other) const; @@ -145,6 +146,18 @@ public: return numParts() == 0; } + uint64_t estimateObjectSizeInBytes() const { + return // Add size of each element in '_replacements' vector. + container_size_helper::estimateObjectSizeInBytes( + _replacements, [](const std::string& s) { return s.capacity(); }, true) + + // Add size of each element in '_variable' vector. + container_size_helper::estimateObjectSizeInBytes(_variable) + + // Add runtime size of '_dotted' string. + _dotted.capacity() + + // Add size of the object. + sizeof(*this); + } + private: // Dotted fields are most often not longer than four parts. We use a mixed structure // here that will not require any extra memory allocation when that is the case. And |