From 4616eae3efe8301ac12574bfc7c6d54338b58bd7 Mon Sep 17 00:00:00 2001 From: Andrew Morrow Date: Sun, 25 Aug 2013 10:55:22 -0400 Subject: SERVER-10159 Re-serialize and cache dotted form in FieldRef on request --- src/mongo/db/field_ref.h | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/mongo/db/field_ref.h') diff --git a/src/mongo/db/field_ref.h b/src/mongo/db/field_ref.h index 681f9873932..06e60c2c165 100644 --- a/src/mongo/db/field_ref.h +++ b/src/mongo/db/field_ref.h @@ -90,7 +90,7 @@ namespace mongo { * Returns a copy of the full dotted field in its current state (i.e., some parts may * have been replaced since the parse() call). */ - std::string dottedField( size_t offset = 0 ) const; + StringData dottedField( size_t offsetFromStart = 0 ) const; /** * Compares the full dotted path represented by this FieldRef to other @@ -117,12 +117,6 @@ namespace mongo { */ size_t numParts() const { return _size; } - /** - * Returns the number of fields parts that were replaced so far. Replacing the same - * fields several times only counts for 1. - */ - size_t numReplaced() const; - 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 @@ -139,20 +133,29 @@ namespace mongo { */ size_t appendPart(const StringData& part); + /** + * Re-assemble _dotted from components, including any replacements in _replacements, + * and update the StringData components in _fixed and _variable to refer to the parts + * of the new _dotted. This is used to make the storage for the current value of this + * FieldRef contiguous so it can be returned as a StringData from the dottedField + * method above. + */ + void reserialize() const; + // number of field parts stored size_t _size; // first kResevedAhead field components - StringData _fixed[kReserveAhead]; + mutable StringData _fixed[kReserveAhead]; // remaining field components - std::vector _variable; + mutable std::vector _variable; // cached dotted name - std::string _dotted; + mutable std::string _dotted; // back memory added with the setPart call pointed to by _fized and _variable - std::vector _replacements; + mutable std::vector _replacements; }; inline bool operator==(const FieldRef& lhs, const FieldRef& rhs) { -- cgit v1.2.1