summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-02-20 11:06:39 -0500
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-02-20 11:06:39 -0500
commitf78f332e0748ac79bb40b490eb6e5462c49da9d0 (patch)
treefbce83b2be8c0f91552c58b0bc00eb71726abbe9
parentabb798f13feebe75f3d1fec94a2d06d64605f00a (diff)
downloadmongo-f78f332e0748ac79bb40b490eb6e5462c49da9d0.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 894b0117393..0523ef6acbb 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 6e01c03390e..6fbd95ec0a9 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 67d2743ac22..5a30cff8fb3 100644
--- a/src/mongo/s/shard_key_pattern.cpp
+++ b/src/mongo/s/shard_key_pattern.cpp
@@ -247,7 +247,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()))