summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/field_path.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/field_path.h')
-rw-r--r--src/mongo/db/pipeline/field_path.h23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/mongo/db/pipeline/field_path.h b/src/mongo/db/pipeline/field_path.h
index d2ee93734e7..c216bdbc0a4 100644
--- a/src/mongo/db/pipeline/field_path.h
+++ b/src/mongo/db/pipeline/field_path.h
@@ -69,9 +69,11 @@ public:
*
* Field names are validated using uassertValidFieldName().
*/
- /* implicit */ FieldPath(std::string inputPath);
- /* implicit */ FieldPath(StringData inputPath) : FieldPath(inputPath.toString()) {}
- /* implicit */ FieldPath(const char* inputPath) : FieldPath(std::string(inputPath)) {}
+ /* implicit */ FieldPath(std::string inputPath, bool precomputeHashes = false);
+ /* implicit */ FieldPath(StringData inputPath, bool precomputeHashes = false)
+ : FieldPath(inputPath.toString(), precomputeHashes) {}
+ /* implicit */ FieldPath(const char* inputPath, bool precomputeHashes = false)
+ : FieldPath(std::string(inputPath), precomputeHashes) {}
/**
* Returns the number of path elements in the field path.
@@ -117,13 +119,8 @@ public:
*/
HashedFieldName getFieldNameHashed(size_t i) const {
dassert(i < getPathLength());
- const auto begin = _fieldPathDotPosition[i] + 1;
- const auto end = _fieldPathDotPosition[i + 1];
- StringData fieldName{&_fieldPath[begin], end - begin};
- if (_fieldHash[i] == kHashUninitialized) {
- _fieldHash[i] = FieldNameHasher()(fieldName);
- }
- return HashedFieldName{fieldName, _fieldHash[i]};
+ invariant(_fieldHash[i] != kHashUninitialized);
+ return HashedFieldName{getFieldName(i), _fieldHash[i]};
}
/**
@@ -177,9 +174,9 @@ private:
// lookup.
std::vector<size_t> _fieldPathDotPosition;
- // Contains the cached hash value for the field. Will initially be set to 'kHashUninitialized',
- // and only generated when it is first retrieved via 'getFieldNameHashed'.
- mutable std::vector<size_t> _fieldHash;
+ // Contains the hash value for the field names if it was requested when creating this path.
+ // Otherwise all elements are set to 'kHashUninitialized'.
+ std::vector<size_t> _fieldHash;
static constexpr std::size_t kHashUninitialized = std::numeric_limits<std::size_t>::max();
};