summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-02-20 11:06:47 -0500
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-02-20 11:06:47 -0500
commit51a2c9eabc44ff9669d11802b9453c1a40e9a32c (patch)
tree659dad64a2c315c99b491cb3c9610c5766da3ac0
parent184abda526230675f5bb67c5b03b343ca2ac5739 (diff)
downloadmongo-51a2c9eabc44ff9669d11802b9453c1a40e9a32c.tar.gz
SERVER-22569 Change findParentEqualityElement() to return by value.
MSVC 2013 doesn't support thread-safe initialization of function-local static-duration objects, so it's possible to return a reference to 'eooElement' prior to the value being fully initialized. (cherry picked from commit 4f1cc51f3e21e4ff76c68e86ecae4e5d138de0aa)
-rw-r--r--src/mongo/db/ops/path_support.cpp11
-rw-r--r--src/mongo/db/ops/path_support.h6
-rw-r--r--src/mongo/s/shard_key_pattern.cpp2
3 files changed, 9 insertions, 10 deletions
diff --git a/src/mongo/db/ops/path_support.cpp b/src/mongo/db/ops/path_support.cpp
index d1e8fa7fcde..0b79a872053 100644
--- a/src/mongo/db/ops/path_support.cpp
+++ b/src/mongo/db/ops/path_support.cpp
@@ -287,9 +287,9 @@ Status setElementAtPath(const FieldRef& path,
}
}
-const BSONElement& findParentEqualityElement(const EqualityMatches& equalities,
- const FieldRef& path,
- int* parentPathParts) {
+BSONElement findParentEqualityElement(const EqualityMatches& equalities,
+ const FieldRef& path,
+ int* parentPathParts) {
// We may have an equality match to an object at a higher point in the pattern path, check
// all path prefixes for equality matches
// ex: path: 'a.b', query : { 'a' : { b : <value> } }
@@ -309,8 +309,7 @@ const BSONElement& findParentEqualityElement(const EqualityMatches& equalities,
}
*parentPathParts = -1;
- static const BSONElement eooElement;
- return eooElement;
+ return BSONElement();
}
/**
@@ -318,7 +317,7 @@ const BSONElement& findParentEqualityElement(const EqualityMatches& equalities,
*/
static Status checkEqualityConflicts(const EqualityMatches& equalities, const FieldRef& path) {
int parentPathPart = -1;
- const BSONElement& parentEl = findParentEqualityElement(equalities, path, &parentPathPart);
+ const BSONElement parentEl = findParentEqualityElement(equalities, path, &parentPathPart);
if (parentEl.eoo())
return Status::OK();
diff --git a/src/mongo/db/ops/path_support.h b/src/mongo/db/ops/path_support.h
index 95d0a3da44c..cebda16aa76 100644
--- a/src/mongo/db/ops/path_support.h
+++ b/src/mongo/db/ops/path_support.h
@@ -170,9 +170,9 @@ Status extractFullEqualityMatches(const MatchExpression& root,
* Path 'a.b.c' has an eqmatch parent of 'a.b' : 1
*
*/
-const BSONElement& findParentEqualityElement(const EqualityMatches& equalities,
- const FieldRef& path,
- int* parentPathParts);
+BSONElement findParentEqualityElement(const EqualityMatches& equalities,
+ const FieldRef& path,
+ int* parentPathParts);
/**
* Adds the BSON values from equality matches into the given document at the equality match
diff --git a/src/mongo/s/shard_key_pattern.cpp b/src/mongo/s/shard_key_pattern.cpp
index 8fca176754c..2071bde5d70 100644
--- a/src/mongo/s/shard_key_pattern.cpp
+++ b/src/mongo/s/shard_key_pattern.cpp
@@ -249,7 +249,7 @@ BSONObj ShardKeyPattern::extractShardKeyFromDoc(const BSONObj& doc) const {
static BSONElement findEqualityElement(const EqualityMatches& equalities, const FieldRef& path) {
int parentPathPart;
- const BSONElement& parentEl =
+ const BSONElement parentEl =
pathsupport::findParentEqualityElement(equalities, path, &parentPathPart);
if (parentPathPart == static_cast<int>(path.numParts()))