summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorQingyang Chen <qingyang.chen@10gen.com>2015-06-24 15:44:52 -0400
committerQingyang Chen <qingyang.chen@10gen.com>2015-06-26 16:50:26 -0400
commitbadc2ac4496c47ae2bbdebf47888a1a5449a22a1 (patch)
tree5b4f1fbc76af3301048ecc14233c1e1143d11b0e /src/mongo
parent9ad1597c2d2ead08a74bd8f53a8458d0f7cb3987 (diff)
downloadmongo-badc2ac4496c47ae2bbdebf47888a1a5449a22a1.tar.gz
SERVER-16889 MatchExpression::shallowClone() return unique_ptr<ME>
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/exec/geo_near.cpp8
-rw-r--r--src/mongo/db/exec/subplan.cpp2
-rw-r--r--src/mongo/db/matcher/expression.h11
-rw-r--r--src/mongo/db/matcher/expression_array.h24
-rw-r--r--src/mongo/db/matcher/expression_geo.cpp12
-rw-r--r--src/mongo/db/matcher/expression_geo.h4
-rw-r--r--src/mongo/db/matcher/expression_leaf.cpp11
-rw-r--r--src/mongo/db/matcher/expression_leaf.h57
-rw-r--r--src/mongo/db/matcher/expression_text.cpp9
-rw-r--r--src/mongo/db/matcher/expression_text.h2
-rw-r--r--src/mongo/db/matcher/expression_tree.h33
-rw-r--r--src/mongo/db/matcher/expression_tree_test.cpp6
-rw-r--r--src/mongo/db/matcher/expression_where.cpp8
-rw-r--r--src/mongo/db/matcher/expression_where_noop.cpp8
-rw-r--r--src/mongo/db/query/canonical_query.cpp4
-rw-r--r--src/mongo/db/query/canonical_query_test.cpp3
-rw-r--r--src/mongo/db/query/plan_enumerator.cpp2
-rw-r--r--src/mongo/db/query/planner_access.cpp44
-rw-r--r--src/mongo/db/query/planner_analysis.cpp4
-rw-r--r--src/mongo/db/query/query_planner.cpp12
-rw-r--r--src/mongo/db/query/query_solution.h2
21 files changed, 139 insertions, 127 deletions
diff --git a/src/mongo/db/exec/geo_near.cpp b/src/mongo/db/exec/geo_near.cpp
index b07113f21fd..7eaeeac9f9a 100644
--- a/src/mongo/db/exec/geo_near.cpp
+++ b/src/mongo/db/exec/geo_near.cpp
@@ -530,7 +530,7 @@ public:
return false;
}
- virtual LeafMatchExpression* shallowClone() const {
+ virtual unique_ptr<MatchExpression> shallowClone() const {
invariant(false);
return NULL;
}
@@ -577,7 +577,7 @@ public:
return true;
}
- virtual MatchExpression* shallowClone() const {
+ virtual unique_ptr<MatchExpression> shallowClone() const {
invariant(false);
return NULL;
}
@@ -790,7 +790,7 @@ StatusWith<NearStage::CoveredInterval*> //
if (_nearParams.filter) {
AndMatchExpression* andMatcher = new AndMatchExpression();
andMatcher->add(keyMatcher);
- andMatcher->add(_nearParams.filter->shallowClone());
+ andMatcher->add(_nearParams.filter->shallowClone().release());
keyMatcher = andMatcher;
}
@@ -927,7 +927,7 @@ public:
return true;
}
- virtual MatchExpression* shallowClone() const {
+ virtual unique_ptr<MatchExpression> shallowClone() const {
invariant(false);
return NULL;
}
diff --git a/src/mongo/db/exec/subplan.cpp b/src/mongo/db/exec/subplan.cpp
index a5b33be1ba9..517ab49825a 100644
--- a/src/mongo/db/exec/subplan.cpp
+++ b/src/mongo/db/exec/subplan.cpp
@@ -230,7 +230,7 @@ Status tagOrChildAccordingToCache(PlanCacheIndexTree* compositeCacheData,
Status SubplanStage::choosePlanForSubqueries(PlanYieldPolicy* yieldPolicy) {
// This is what we annotate with the index selections and then turn into a solution.
unique_ptr<OrMatchExpression> orExpr(
- static_cast<OrMatchExpression*>(_query->root()->shallowClone()));
+ static_cast<OrMatchExpression*>(_query->root()->shallowClone().release()));
// This is the skeleton of index selections that is inserted into the cache.
unique_ptr<PlanCacheIndexTree> cacheData(new PlanCacheIndexTree());
diff --git a/src/mongo/db/matcher/expression.h b/src/mongo/db/matcher/expression.h
index 3911bd0c863..bc2a0410839 100644
--- a/src/mongo/db/matcher/expression.h
+++ b/src/mongo/db/matcher/expression.h
@@ -37,6 +37,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/matcher/matchable.h"
#include "mongo/db/matcher/match_details.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
@@ -176,7 +177,7 @@ public:
}
// XXX: document
- virtual MatchExpression* shallowClone() const = 0;
+ virtual std::unique_ptr<MatchExpression> shallowClone() const = 0;
// XXX document
virtual bool equivalent(const MatchExpression* other) const = 0;
@@ -253,8 +254,8 @@ public:
return true;
}
- virtual MatchExpression* shallowClone() const {
- return new AtomicMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ return stdx::make_unique<AtomicMatchExpression>();
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
@@ -278,8 +279,8 @@ public:
return false;
}
- virtual MatchExpression* shallowClone() const {
- return new FalseMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ return stdx::make_unique<FalseMatchExpression>();
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
diff --git a/src/mongo/db/matcher/expression_array.h b/src/mongo/db/matcher/expression_array.h
index f9bcfd53167..0776bd5a3cf 100644
--- a/src/mongo/db/matcher/expression_array.h
+++ b/src/mongo/db/matcher/expression_array.h
@@ -74,13 +74,14 @@ public:
bool matchesArray(const BSONObj& anArray, MatchDetails* details) const;
- virtual ElemMatchObjectMatchExpression* shallowClone() const {
- ElemMatchObjectMatchExpression* e = new ElemMatchObjectMatchExpression();
- e->init(path(), _sub->shallowClone());
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ElemMatchObjectMatchExpression> e =
+ stdx::make_unique<ElemMatchObjectMatchExpression>();
+ e->init(path(), _sub->shallowClone().release());
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual void debugString(StringBuilder& debug, int level) const;
@@ -110,16 +111,17 @@ public:
bool matchesArray(const BSONObj& anArray, MatchDetails* details) const;
- virtual ElemMatchValueMatchExpression* shallowClone() const {
- ElemMatchValueMatchExpression* e = new ElemMatchValueMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ElemMatchValueMatchExpression> e =
+ stdx::make_unique<ElemMatchValueMatchExpression>();
e->init(path());
for (size_t i = 0; i < _subs.size(); ++i) {
- e->add(_subs[i]->shallowClone());
+ e->add(_subs[i]->shallowClone().release());
}
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual void debugString(StringBuilder& debug, int level) const;
@@ -149,13 +151,13 @@ public:
SizeMatchExpression() : ArrayMatchingMatchExpression(SIZE) {}
Status init(StringData path, int size);
- virtual SizeMatchExpression* shallowClone() const {
- SizeMatchExpression* e = new SizeMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<SizeMatchExpression> e = stdx::make_unique<SizeMatchExpression>();
e->init(path(), _size);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual bool matchesArray(const BSONObj& anArray, MatchDetails* details) const;
diff --git a/src/mongo/db/matcher/expression_geo.cpp b/src/mongo/db/matcher/expression_geo.cpp
index 1cca795b743..282710c463d 100644
--- a/src/mongo/db/matcher/expression_geo.cpp
+++ b/src/mongo/db/matcher/expression_geo.cpp
@@ -376,14 +376,14 @@ bool GeoMatchExpression::equivalent(const MatchExpression* other) const {
return _rawObj == realOther->_rawObj;
}
-LeafMatchExpression* GeoMatchExpression::shallowClone() const {
- GeoMatchExpression* next = new GeoMatchExpression();
+std::unique_ptr<MatchExpression> GeoMatchExpression::shallowClone() const {
+ std::unique_ptr<GeoMatchExpression> next = stdx::make_unique<GeoMatchExpression>();
next->init(path(), NULL, _rawObj);
next->_query = _query;
if (getTag()) {
next->setTag(getTag()->clone());
}
- return next;
+ return std::move(next);
}
//
@@ -432,13 +432,13 @@ bool GeoNearMatchExpression::equivalent(const MatchExpression* other) const {
return _rawObj == realOther->_rawObj;
}
-LeafMatchExpression* GeoNearMatchExpression::shallowClone() const {
- GeoNearMatchExpression* next = new GeoNearMatchExpression();
+std::unique_ptr<MatchExpression> GeoNearMatchExpression::shallowClone() const {
+ std::unique_ptr<GeoNearMatchExpression> next = stdx::make_unique<GeoNearMatchExpression>();
next->init(path(), NULL, _rawObj);
next->_query = _query;
if (getTag()) {
next->setTag(getTag()->clone());
}
- return next;
+ return std::move(next);
}
}
diff --git a/src/mongo/db/matcher/expression_geo.h b/src/mongo/db/matcher/expression_geo.h
index 197bb794973..7cbb6fcbfe8 100644
--- a/src/mongo/db/matcher/expression_geo.h
+++ b/src/mongo/db/matcher/expression_geo.h
@@ -94,7 +94,7 @@ public:
virtual bool equivalent(const MatchExpression* other) const;
- virtual LeafMatchExpression* shallowClone() const;
+ virtual std::unique_ptr<MatchExpression> shallowClone() const;
const GeoExpression& getGeoExpression() const {
return *_query;
@@ -168,7 +168,7 @@ public:
virtual bool equivalent(const MatchExpression* other) const;
- virtual LeafMatchExpression* shallowClone() const;
+ virtual std::unique_ptr<MatchExpression> shallowClone() const;
const GeoNearExpression& getData() const {
return *_query;
diff --git a/src/mongo/db/matcher/expression_leaf.cpp b/src/mongo/db/matcher/expression_leaf.cpp
index 8284ca8f3ab..e3b75f8d517 100644
--- a/src/mongo/db/matcher/expression_leaf.cpp
+++ b/src/mongo/db/matcher/expression_leaf.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/field_ref.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/matcher/path.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
@@ -511,7 +512,7 @@ void ArrayFilterEntries::copyTo(ArrayFilterEntries& toFillIn) const {
toFillIn._equalities = _equalities;
for (unsigned i = 0; i < _regexes.size(); i++)
toFillIn._regexes.push_back(
- static_cast<RegexMatchExpression*>(_regexes[i]->shallowClone()));
+ static_cast<RegexMatchExpression*>(_regexes[i]->shallowClone().release()));
}
void ArrayFilterEntries::debugString(StringBuilder& debug) const {
@@ -603,13 +604,13 @@ bool InMatchExpression::equivalent(const MatchExpression* other) const {
return path() == realOther->path() && _arrayEntries.equivalent(realOther->_arrayEntries);
}
-LeafMatchExpression* InMatchExpression::shallowClone() const {
- InMatchExpression* next = new InMatchExpression();
- copyTo(next);
+std::unique_ptr<MatchExpression> InMatchExpression::shallowClone() const {
+ std::unique_ptr<InMatchExpression> next = stdx::make_unique<InMatchExpression>();
+ copyTo(next.get());
if (getTag()) {
next->setTag(getTag()->clone());
}
- return next;
+ return std::move(next);
}
void InMatchExpression::copyTo(InMatchExpression* toFillIn) const {
diff --git a/src/mongo/db/matcher/expression_leaf.h b/src/mongo/db/matcher/expression_leaf.h
index e0e61ac11ea..fc939cc0af1 100644
--- a/src/mongo/db/matcher/expression_leaf.h
+++ b/src/mongo/db/matcher/expression_leaf.h
@@ -34,6 +34,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonmisc.h"
#include "mongo/db/matcher/expression.h"
+#include "mongo/stdx/memory.h"
namespace pcrecpp {
class RE;
@@ -114,65 +115,65 @@ protected:
class EqualityMatchExpression : public ComparisonMatchExpression {
public:
EqualityMatchExpression() : ComparisonMatchExpression(EQ) {}
- virtual LeafMatchExpression* shallowClone() const {
- ComparisonMatchExpression* e = new EqualityMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<EqualityMatchExpression>();
e->init(path(), _rhs);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
};
class LTEMatchExpression : public ComparisonMatchExpression {
public:
LTEMatchExpression() : ComparisonMatchExpression(LTE) {}
- virtual LeafMatchExpression* shallowClone() const {
- ComparisonMatchExpression* e = new LTEMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<LTEMatchExpression>();
e->init(path(), _rhs);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
};
class LTMatchExpression : public ComparisonMatchExpression {
public:
LTMatchExpression() : ComparisonMatchExpression(LT) {}
- virtual LeafMatchExpression* shallowClone() const {
- ComparisonMatchExpression* e = new LTMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<LTMatchExpression>();
e->init(path(), _rhs);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
};
class GTMatchExpression : public ComparisonMatchExpression {
public:
GTMatchExpression() : ComparisonMatchExpression(GT) {}
- virtual LeafMatchExpression* shallowClone() const {
- ComparisonMatchExpression* e = new GTMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<GTMatchExpression>();
e->init(path(), _rhs);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
};
class GTEMatchExpression : public ComparisonMatchExpression {
public:
GTEMatchExpression() : ComparisonMatchExpression(GTE) {}
- virtual LeafMatchExpression* shallowClone() const {
- ComparisonMatchExpression* e = new GTEMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ComparisonMatchExpression> e = stdx::make_unique<GTEMatchExpression>();
e->init(path(), _rhs);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
};
@@ -195,13 +196,13 @@ public:
Status init(StringData path, StringData regex, StringData options);
Status init(StringData path, const BSONElement& e);
- virtual LeafMatchExpression* shallowClone() const {
- RegexMatchExpression* e = new RegexMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<RegexMatchExpression> e = stdx::make_unique<RegexMatchExpression>();
e->init(path(), _regex, _flags);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual bool matchesSingleElement(const BSONElement& e) const;
@@ -233,13 +234,13 @@ public:
Status init(StringData path, int divisor, int remainder);
- virtual LeafMatchExpression* shallowClone() const {
- ModMatchExpression* m = new ModMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ModMatchExpression> m = stdx::make_unique<ModMatchExpression>();
m->init(path(), _divisor, _remainder);
if (getTag()) {
m->setTag(getTag()->clone());
}
- return m;
+ return std::move(m);
}
virtual bool matchesSingleElement(const BSONElement& e) const;
@@ -268,13 +269,13 @@ public:
Status init(StringData path);
- virtual LeafMatchExpression* shallowClone() const {
- ExistsMatchExpression* e = new ExistsMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<ExistsMatchExpression> e = stdx::make_unique<ExistsMatchExpression>();
e->init(path());
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual bool matchesSingleElement(const BSONElement& e) const;
@@ -352,7 +353,7 @@ public:
InMatchExpression() : LeafMatchExpression(MATCH_IN) {}
Status init(StringData path);
- virtual LeafMatchExpression* shallowClone() const;
+ virtual std::unique_ptr<MatchExpression> shallowClone() const;
ArrayFilterEntries* getArrayFilterEntries() {
return &_arrayEntries;
@@ -391,13 +392,13 @@ public:
Status init(StringData path, int type);
- virtual MatchExpression* shallowClone() const {
- TypeMatchExpression* e = new TypeMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<TypeMatchExpression> e = stdx::make_unique<TypeMatchExpression>();
e->init(_path, _type);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual bool matchesSingleElement(const BSONElement& e) const;
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp
index e1f1ccd065f..34ea527e6ca 100644
--- a/src/mongo/db/matcher/expression_text.cpp
+++ b/src/mongo/db/matcher/expression_text.cpp
@@ -30,10 +30,13 @@
#include "mongo/platform/basic.h"
#include "mongo/db/matcher/expression_text.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
using std::string;
+using std::unique_ptr;
+using stdx::make_unique;
Status TextMatchExpression::init(const string& query, const string& language, bool caseSensitive) {
_query = query;
@@ -88,12 +91,12 @@ bool TextMatchExpression::equivalent(const MatchExpression* other) const {
return true;
}
-LeafMatchExpression* TextMatchExpression::shallowClone() const {
- TextMatchExpression* next = new TextMatchExpression();
+unique_ptr<MatchExpression> TextMatchExpression::shallowClone() const {
+ unique_ptr<TextMatchExpression> next = make_unique<TextMatchExpression>();
next->init(_query, _language, _caseSensitive);
if (getTag()) {
next->setTag(getTag()->clone());
}
- return next;
+ return std::move(next);
}
}
diff --git a/src/mongo/db/matcher/expression_text.h b/src/mongo/db/matcher/expression_text.h
index 3841bf4a608..3dae52c9ed6 100644
--- a/src/mongo/db/matcher/expression_text.h
+++ b/src/mongo/db/matcher/expression_text.h
@@ -51,7 +51,7 @@ public:
virtual bool equivalent(const MatchExpression* other) const;
- virtual LeafMatchExpression* shallowClone() const;
+ virtual std::unique_ptr<MatchExpression> shallowClone() const;
const std::string& getQuery() const {
return _query;
diff --git a/src/mongo/db/matcher/expression_tree.h b/src/mongo/db/matcher/expression_tree.h
index 5069045727c..0f4b8018523 100644
--- a/src/mongo/db/matcher/expression_tree.h
+++ b/src/mongo/db/matcher/expression_tree.h
@@ -88,15 +88,15 @@ public:
virtual bool matches(const MatchableDocument* doc, MatchDetails* details = 0) const;
virtual bool matchesSingleElement(const BSONElement& e) const;
- virtual MatchExpression* shallowClone() const {
- AndMatchExpression* self = new AndMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<AndMatchExpression> self = stdx::make_unique<AndMatchExpression>();
for (size_t i = 0; i < numChildren(); ++i) {
- self->add(getChild(i)->shallowClone());
+ self->add(getChild(i)->shallowClone().release());
}
if (getTag()) {
self->setTag(getTag()->clone());
}
- return self;
+ return std::move(self);
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
@@ -112,15 +112,15 @@ public:
virtual bool matches(const MatchableDocument* doc, MatchDetails* details = 0) const;
virtual bool matchesSingleElement(const BSONElement& e) const;
- virtual MatchExpression* shallowClone() const {
- OrMatchExpression* self = new OrMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<OrMatchExpression> self = stdx::make_unique<OrMatchExpression>();
for (size_t i = 0; i < numChildren(); ++i) {
- self->add(getChild(i)->shallowClone());
+ self->add(getChild(i)->shallowClone().release());
}
if (getTag()) {
self->setTag(getTag()->clone());
}
- return self;
+ return std::move(self);
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
@@ -136,15 +136,15 @@ public:
virtual bool matches(const MatchableDocument* doc, MatchDetails* details = 0) const;
virtual bool matchesSingleElement(const BSONElement& e) const;
- virtual MatchExpression* shallowClone() const {
- NorMatchExpression* self = new NorMatchExpression();
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<NorMatchExpression> self = stdx::make_unique<NorMatchExpression>();
for (size_t i = 0; i < numChildren(); ++i) {
- self->add(getChild(i)->shallowClone());
+ self->add(getChild(i)->shallowClone().release());
}
if (getTag()) {
self->setTag(getTag()->clone());
}
- return self;
+ return std::move(self);
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
@@ -164,14 +164,13 @@ public:
return Status::OK();
}
- virtual MatchExpression* shallowClone() const {
- NotMatchExpression* self = new NotMatchExpression();
- MatchExpression* child = _exp->shallowClone();
- self->init(child);
+ virtual std::unique_ptr<MatchExpression> shallowClone() const {
+ std::unique_ptr<NotMatchExpression> self = stdx::make_unique<NotMatchExpression>();
+ self->init(_exp->shallowClone().release());
if (getTag()) {
self->setTag(getTag()->clone());
}
- return self;
+ return std::move(self);
}
virtual bool matches(const MatchableDocument* doc, MatchDetails* details = 0) const {
diff --git a/src/mongo/db/matcher/expression_tree_test.cpp b/src/mongo/db/matcher/expression_tree_test.cpp
index a63439a1de2..17ec2f9e2ac 100644
--- a/src/mongo/db/matcher/expression_tree_test.cpp
+++ b/src/mongo/db/matcher/expression_tree_test.cpp
@@ -545,11 +545,11 @@ TEST(NorOp, Equivalent) {
ASSERT(sub2.init("b", baseOperand2["b"]).isOK());
NorMatchExpression e1;
- e1.add(sub1.shallowClone());
- e1.add(sub2.shallowClone());
+ e1.add(sub1.shallowClone().release());
+ e1.add(sub2.shallowClone().release());
NorMatchExpression e2;
- e2.add(sub1.shallowClone());
+ e2.add(sub1.shallowClone().release());
ASSERT(e1.equivalent(&e1));
ASSERT(!e1.equivalent(&e2));
diff --git a/src/mongo/db/matcher/expression_where.cpp b/src/mongo/db/matcher/expression_where.cpp
index f3d99b79136..22985eb10e4 100644
--- a/src/mongo/db/matcher/expression_where.cpp
+++ b/src/mongo/db/matcher/expression_where.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/scripting/engine.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
@@ -46,6 +47,7 @@ using std::unique_ptr;
using std::endl;
using std::string;
using std::stringstream;
+using stdx::make_unique;
class WhereMatchExpression : public MatchExpression {
public:
@@ -65,13 +67,13 @@ public:
return false;
}
- virtual MatchExpression* shallowClone() const {
- WhereMatchExpression* e = new WhereMatchExpression(_txn);
+ virtual unique_ptr<MatchExpression> shallowClone() const {
+ unique_ptr<WhereMatchExpression> e = make_unique<WhereMatchExpression>(_txn);
e->init(_dbName, _code, _userScope);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
diff --git a/src/mongo/db/matcher/expression_where_noop.cpp b/src/mongo/db/matcher/expression_where_noop.cpp
index d505542e818..fcda8d6a006 100644
--- a/src/mongo/db/matcher/expression_where_noop.cpp
+++ b/src/mongo/db/matcher/expression_where_noop.cpp
@@ -32,11 +32,13 @@
#include "mongo/base/init.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/matcher/expression_parser.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
using std::unique_ptr;
using std::string;
+using stdx::make_unique;
/**
* Bogus no-op $where match expression to parse $where in mongos,
@@ -59,13 +61,13 @@ public:
return false;
}
- virtual MatchExpression* shallowClone() const {
- WhereNoOpMatchExpression* e = new WhereNoOpMatchExpression();
+ virtual unique_ptr<MatchExpression> shallowClone() const {
+ unique_ptr<WhereNoOpMatchExpression> e = make_unique<WhereNoOpMatchExpression>();
e->init(_code);
if (getTag()) {
e->setTag(getTag()->clone());
}
- return e;
+ return std::move(e);
}
virtual void debugString(StringBuilder& debug, int level = 0) const;
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp
index 701a5fd2545..9392c62c09b 100644
--- a/src/mongo/db/query/canonical_query.cpp
+++ b/src/mongo/db/query/canonical_query.cpp
@@ -258,7 +258,7 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize(
// Make the CQ we'll hopefully return.
std::unique_ptr<CanonicalQuery> cq(new CanonicalQuery());
Status initStatus =
- cq->init(lpqStatus.getValue().release(), whereCallback, root->shallowClone());
+ cq->init(lpqStatus.getValue().release(), whereCallback, root->shallowClone().release());
if (!initStatus.isOK()) {
return initStatus;
@@ -596,7 +596,7 @@ MatchExpression* CanonicalQuery::logicalRewrite(MatchExpression* tree) {
for (size_t i = 0; i < orChildren.size(); ++i) {
AndMatchExpression* ama = new AndMatchExpression();
ama->add(orChildren[i]);
- ama->add(tree->shallowClone());
+ ama->add(tree->shallowClone().release());
orChildren[i] = ama;
}
delete tree;
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp
index a754cde8502..ff4df2026d9 100644
--- a/src/mongo/db/query/canonical_query_test.cpp
+++ b/src/mongo/db/query/canonical_query_test.cpp
@@ -484,7 +484,8 @@ TEST(CanonicalQueryTest, RewriteNoDoubleOr) {
string queryStr = "{$or:[{a:1}, {b:1}], $or:[{c:1}, {d:1}], e:1}";
BSONObj queryObj = fromjson(queryStr);
unique_ptr<MatchExpression> base(parseMatchExpression(queryObj));
- unique_ptr<MatchExpression> rewrite(CanonicalQuery::logicalRewrite(base->shallowClone()));
+ unique_ptr<MatchExpression> rewrite(
+ CanonicalQuery::logicalRewrite(base->shallowClone().release()));
assertEquivalent(queryStr.c_str(), base.get(), rewrite.get());
}
diff --git a/src/mongo/db/query/plan_enumerator.cpp b/src/mongo/db/query/plan_enumerator.cpp
index 20049790c0b..ebaef1d5308 100644
--- a/src/mongo/db/query/plan_enumerator.cpp
+++ b/src/mongo/db/query/plan_enumerator.cpp
@@ -175,7 +175,7 @@ bool PlanEnumerator::getNext(MatchExpression** tree) {
// Tag with our first solution.
tagMemo(memoIDForNode(_root));
- *tree = _root->shallowClone();
+ *tree = _root->shallowClone().release();
tagForSort(*tree);
sortUsingTags(*tree);
diff --git a/src/mongo/db/query/planner_access.cpp b/src/mongo/db/query/planner_access.cpp
index 1c059933f17..c91b93bb785 100644
--- a/src/mongo/db/query/planner_access.cpp
+++ b/src/mongo/db/query/planner_access.cpp
@@ -42,6 +42,7 @@
#include "mongo/db/query/query_knobs.h"
#include "mongo/db/query/query_planner.h"
#include "mongo/db/query/query_planner_common.h"
+#include "mongo/stdx/memory.h"
#include "mongo/util/log.h"
namespace {
@@ -61,6 +62,7 @@ namespace mongo {
using std::unique_ptr;
using std::vector;
+using stdx::make_unique;
// static
QuerySolutionNode* QueryPlannerAccess::makeCollectionScan(const CanonicalQuery& query,
@@ -69,7 +71,7 @@ QuerySolutionNode* QueryPlannerAccess::makeCollectionScan(const CanonicalQuery&
// Make the (only) node, a collection scan.
CollectionScanNode* csn = new CollectionScanNode();
csn->name = query.ns();
- csn->filter.reset(query.root()->shallowClone());
+ csn->filter = std::move(query.root()->shallowClone());
csn->tailable = tailable;
csn->maxScan = query.getParsed().getMaxScan();
@@ -825,7 +827,7 @@ QuerySolutionNode* QueryPlannerAccess::buildIndexedAnd(const CanonicalQuery& que
// XXX: This block is a hack to accommodate the storage layer concurrency model.
std::unique_ptr<MatchExpression> clonedRoot;
if (params.options & QueryPlannerParams::CANNOT_TRIM_IXISECT) {
- clonedRoot.reset(root->shallowClone());
+ clonedRoot = std::move(root->shallowClone());
}
vector<QuerySolutionNode*> ixscanNodes;
@@ -1126,7 +1128,7 @@ QuerySolutionNode* QueryPlannerAccess::scanWholeIndex(const IndexEntry& index,
QuerySolutionNode* solnRoot = NULL;
// Build an ixscan over the id index, use it, and return it.
- IndexScanNode* isn = new IndexScanNode();
+ unique_ptr<IndexScanNode> isn = make_unique<IndexScanNode>();
isn->indexKeyPattern = index.keyPattern;
isn->indexIsMultiKey = index.multikey;
isn->maxScan = query.getParsed().getMaxScan();
@@ -1135,23 +1137,22 @@ QuerySolutionNode* QueryPlannerAccess::scanWholeIndex(const IndexEntry& index,
IndexBoundsBuilder::allValuesBounds(index.keyPattern, &isn->bounds);
if (-1 == direction) {
- QueryPlannerCommon::reverseScans(isn);
+ QueryPlannerCommon::reverseScans(isn.get());
isn->direction = -1;
}
- MatchExpression* filter = query.root()->shallowClone();
+ unique_ptr<MatchExpression> filter = std::move(query.root()->shallowClone());
// If it's find({}) remove the no-op root.
if (MatchExpression::AND == filter->matchType() && (0 == filter->numChildren())) {
- delete filter;
- solnRoot = isn;
+ solnRoot = isn.release();
} else {
// TODO: We may not need to do the fetch if the predicates in root are covered. But
// for now it's safe (though *maybe* slower).
- FetchNode* fetch = new FetchNode();
- fetch->filter.reset(filter);
- fetch->children.push_back(isn);
- solnRoot = fetch;
+ unique_ptr<FetchNode> fetch = make_unique<FetchNode>();
+ fetch->filter = std::move(filter);
+ fetch->children.push_back(isn.release());
+ solnRoot = fetch.release();
}
return solnRoot;
@@ -1172,17 +1173,17 @@ void QueryPlannerAccess::addFilterToSolutionNode(QuerySolutionNode* node,
// The 'node' already has a filter that does not match 'type'. If 'type' is AND, then
// combine 'match' with the existing filter by adding an AND. If 'type' is OR, combine
// by adding an OR node.
- ListOfMatchExpression* listFilter;
+ unique_ptr<ListOfMatchExpression> listFilter;
if (MatchExpression::AND == type) {
- listFilter = new AndMatchExpression();
+ listFilter = make_unique<AndMatchExpression>();
} else {
verify(MatchExpression::OR == type);
- listFilter = new OrMatchExpression();
+ listFilter = make_unique<OrMatchExpression>();
}
- MatchExpression* oldFilter = node->filter->shallowClone();
- listFilter->add(oldFilter);
+ unique_ptr<MatchExpression> oldFilter = std::move(node->filter->shallowClone());
+ listFilter->add(oldFilter.release());
listFilter->add(match);
- node->filter.reset(listFilter);
+ node->filter = std::move(listFilter);
}
}
@@ -1274,19 +1275,18 @@ QuerySolutionNode* QueryPlannerAccess::makeIndexScan(const IndexEntry& index,
isn->bounds.endKey = endKey;
isn->bounds.endKeyInclusive = false;
- MatchExpression* filter = query.root()->shallowClone();
+ unique_ptr<MatchExpression> filter = std::move(query.root()->shallowClone());
// If it's find({}) remove the no-op root.
if (MatchExpression::AND == filter->matchType() && (0 == filter->numChildren())) {
- delete filter;
solnRoot = isn;
} else {
// TODO: We may not need to do the fetch if the predicates in root are covered. But
// for now it's safe (though *maybe* slower).
- FetchNode* fetch = new FetchNode();
- fetch->filter.reset(filter);
+ unique_ptr<FetchNode> fetch = make_unique<FetchNode>();
+ fetch->filter = std::move(filter);
fetch->children.push_back(isn);
- solnRoot = fetch;
+ solnRoot = fetch.release();
}
return solnRoot;
diff --git a/src/mongo/db/query/planner_analysis.cpp b/src/mongo/db/query/planner_analysis.cpp
index 4026d62572a..a7ab20ad54a 100644
--- a/src/mongo/db/query/planner_analysis.cpp
+++ b/src/mongo/db/query/planner_analysis.cpp
@@ -209,7 +209,7 @@ void explodeScan(IndexScanNode* isn,
// Copy the filter, if there is one.
if (isn->filter.get()) {
- child->filter.reset(isn->filter->shallowClone());
+ child->filter = std::move(isn->filter->shallowClone());
}
// Create child bounds.
@@ -610,7 +610,7 @@ QuerySolution* QueryPlannerAnalysis::analyzeDataAccess(const CanonicalQuery& que
KeepMutationsNode* keep = new KeepMutationsNode();
// We must run the entire expression tree to make sure the document is still valid.
- keep->filter.reset(query.root()->shallowClone());
+ keep->filter = std::move(query.root()->shallowClone());
if (STAGE_SORT == solnRoot->getType()) {
// We want to insert the invalidated results before the sort stage, if there is one.
diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
index bb5a163835c..073e60f10fa 100644
--- a/src/mongo/db/query/query_planner.cpp
+++ b/src/mongo/db/query/query_planner.cpp
@@ -371,7 +371,7 @@ Status QueryPlanner::planFromCache(const CanonicalQuery& query,
// cases, and we proceed by using the PlanCacheIndexTree to tag the query tree.
// Create a copy of the expression tree. We use cachedSoln to annotate this with indices.
- MatchExpression* clone = query.root()->shallowClone();
+ unique_ptr<MatchExpression> clone = std::move(query.root()->shallowClone());
LOG(5) << "Tagging the match expression according to cache data: " << endl
<< "Filter:" << endl
@@ -388,20 +388,20 @@ Status QueryPlanner::planFromCache(const CanonicalQuery& query,
LOG(5) << "Index " << i << ": " << ie.keyPattern.toString() << endl;
}
- Status s = tagAccordingToCache(clone, winnerCacheData.tree.get(), indexMap);
+ Status s = tagAccordingToCache(clone.get(), winnerCacheData.tree.get(), indexMap);
if (!s.isOK()) {
return s;
}
// The planner requires a defined sort order.
- sortUsingTags(clone);
+ sortUsingTags(clone.get());
LOG(5) << "Tagged tree:" << endl
<< clone->toString();
- // Use the cached index assignments to build solnRoot. Takes ownership of clone.
- QuerySolutionNode* solnRoot =
- QueryPlannerAccess::buildIndexedDataAccess(query, clone, false, params.indices, params);
+ // Use the cached index assignments to build solnRoot.
+ QuerySolutionNode* solnRoot = QueryPlannerAccess::buildIndexedDataAccess(
+ query, clone.release(), false, params.indices, params);
if (!solnRoot) {
return Status(ErrorCodes::BadValue,
diff --git a/src/mongo/db/query/query_solution.h b/src/mongo/db/query/query_solution.h
index cd8cbbbd25a..9cef086ff65 100644
--- a/src/mongo/db/query/query_solution.h
+++ b/src/mongo/db/query/query_solution.h
@@ -140,7 +140,7 @@ struct QuerySolutionNode {
other->children.push_back(this->children[i]->clone());
}
if (NULL != this->filter) {
- other->filter.reset(this->filter->shallowClone());
+ other->filter = std::move(this->filter->shallowClone());
}
}