diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2019-03-26 10:01:50 -0400 |
---|---|---|
committer | Ted Tuckman <ted.tuckman@mongodb.com> | 2019-03-27 08:30:16 -0400 |
commit | 31568981a81fe446d57f8e8892cf690dff37c7a6 (patch) | |
tree | 5b848366dd695fd5b7fbe1b3cadc795adf6a41d6 /src | |
parent | 3aecf68d4b9cbdb3a9bde86bde945c733f50efe7 (diff) | |
download | mongo-31568981a81fe446d57f8e8892cf690dff37c7a6.tar.gz |
SERVER-39257 Move FieldRefTempAppend to FieldRef class
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/field_ref.h | 18 | ||||
-rw-r--r-- | src/mongo/db/update/update_array_node.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/update/update_array_node.h | 3 | ||||
-rw-r--r-- | src/mongo/db/update/update_internal_node.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/update/update_internal_node.h | 18 | ||||
-rw-r--r-- | src/mongo/db/update/update_object_node.h | 4 |
6 files changed, 27 insertions, 25 deletions
diff --git a/src/mongo/db/field_ref.h b/src/mongo/db/field_ref.h index 32066ed98a5..736f843ec34 100644 --- a/src/mongo/db/field_ref.h +++ b/src/mongo/db/field_ref.h @@ -52,6 +52,24 @@ namespace mongo { class FieldRef { public: /** + * Helper class for appending to a FieldRef for the duration of the current scope and then + * restoring the FieldRef at the end of the scope. + */ + class FieldRefTempAppend { + public: + FieldRefTempAppend(FieldRef& fieldRef, StringData part) : _fieldRef(fieldRef) { + _fieldRef.appendPart(part); + } + + ~FieldRefTempAppend() { + _fieldRef.removeLastPart(); + } + + private: + FieldRef& _fieldRef; + }; + + /** * Returns true if the argument is a numeric string which is eligible to act as the key name for * an element in a BSON array; in other words, the string matches the regex ^(0|[1-9]+[0-9]*)$. */ diff --git a/src/mongo/db/update/update_array_node.cpp b/src/mongo/db/update/update_array_node.cpp index 8730c05a0ad..d895272e8f3 100644 --- a/src/mongo/db/update/update_array_node.cpp +++ b/src/mongo/db/update/update_array_node.cpp @@ -116,7 +116,8 @@ UpdateNode::ApplyResult UpdateArrayNode::apply(ApplyParams applyParams) const { // Merge all of the updates for this array element. invariant(updates->second.size() > 0); auto mergedChild = updates->second[0]; - FieldRefTempAppend tempAppend(*(applyParams.pathTaken), childElement.getFieldName()); + FieldRef::FieldRefTempAppend tempAppend(*(applyParams.pathTaken), + childElement.getFieldName()); for (size_t j = 1; j < updates->second.size(); ++j) { // Use the cached merge result, if it is available. @@ -172,8 +173,8 @@ UpdateNode::ApplyResult UpdateArrayNode::apply(ApplyParams applyParams) const { // Log the modified array element. invariant(modifiedElement); - FieldRefTempAppend tempAppend(*(applyParams.pathTaken), - modifiedElement->getFieldName()); + FieldRef::FieldRefTempAppend tempAppend(*(applyParams.pathTaken), + modifiedElement->getFieldName()); auto logElement = applyParams.logBuilder->getDocument().makeElementWithNewFieldName( applyParams.pathTaken->dottedField(), *modifiedElement); invariant(logElement.ok()); diff --git a/src/mongo/db/update/update_array_node.h b/src/mongo/db/update/update_array_node.h index 88f3996afa1..2dfad295f62 100644 --- a/src/mongo/db/update/update_array_node.h +++ b/src/mongo/db/update/update_array_node.h @@ -86,7 +86,8 @@ public: std::map<std::string, std::vector<std::pair<std::string, BSONObj>>>* operatorOrientedUpdates) const final { for (const auto & [ pathSuffix, child ] : _children) { - FieldRefTempAppend tempAppend(*currentPath, toArrayFilterIdentifier(pathSuffix)); + FieldRef::FieldRefTempAppend tempAppend(*currentPath, + toArrayFilterIdentifier(pathSuffix)); child->produceSerializationMap(currentPath, operatorOrientedUpdates); } } diff --git a/src/mongo/db/update/update_internal_node.cpp b/src/mongo/db/update/update_internal_node.cpp index 2ae1ef3c8e3..95cc60eda8e 100644 --- a/src/mongo/db/update/update_internal_node.cpp +++ b/src/mongo/db/update/update_internal_node.cpp @@ -85,7 +85,7 @@ std::unique_ptr<UpdateNode> UpdateInternalNode::copyOrMergeAsNecessary( } else if (!rightNode) { return leftNode->clone(); } else { - FieldRefTempAppend tempAppend( + FieldRef::FieldRefTempAppend tempAppend( *pathTaken, wrapFieldNameAsArrayFilterIdentifier ? toArrayFilterIdentifier(nextField) : nextField); return UpdateNode::createUpdateNodeByMerging(*leftNode, *rightNode, pathTaken); diff --git a/src/mongo/db/update/update_internal_node.h b/src/mongo/db/update/update_internal_node.h index cfb787d2c5a..9cadd04fc57 100644 --- a/src/mongo/db/update/update_internal_node.h +++ b/src/mongo/db/update/update_internal_node.h @@ -44,24 +44,6 @@ namespace mongo { */ class UpdateInternalNode : public UpdateNode { public: - /** - * Helper class for appending to a FieldRef for the duration of the current scope and then - * restoring the FieldRef at the end of the scope. - */ - class FieldRefTempAppend { - public: - FieldRefTempAppend(FieldRef& fieldRef, StringData part) : _fieldRef(fieldRef) { - _fieldRef.appendPart(part); - } - - ~FieldRefTempAppend() { - _fieldRef.removeLastPart(); - } - - private: - FieldRef& _fieldRef; - }; - UpdateInternalNode(UpdateNode::Type type) : UpdateNode(type) {} /** diff --git a/src/mongo/db/update/update_object_node.h b/src/mongo/db/update/update_object_node.h index 2eee5c4d8f3..e09934148ca 100644 --- a/src/mongo/db/update/update_object_node.h +++ b/src/mongo/db/update/update_object_node.h @@ -111,12 +111,12 @@ public: std::map<std::string, std::vector<std::pair<std::string, BSONObj>>>* operatorOrientedUpdates) const final { for (const auto & [ pathSuffix, child ] : _children) { - FieldRefTempAppend tempAppend(*currentPath, pathSuffix); + FieldRef::FieldRefTempAppend tempAppend(*currentPath, pathSuffix); child->produceSerializationMap(currentPath, operatorOrientedUpdates); } // Object nodes have a positional child that must be accounted for. if (_positionalChild) { - FieldRefTempAppend tempAppend(*currentPath, "$"); + FieldRef::FieldRefTempAppend tempAppend(*currentPath, "$"); _positionalChild->produceSerializationMap(currentPath, operatorOrientedUpdates); } } |