diff options
Diffstat (limited to 'src')
42 files changed, 258 insertions, 325 deletions
diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp index 6dc24b6a8d6..d58906dc8d6 100644 --- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp @@ -278,7 +278,7 @@ Status AuthzManagerExternalStateMock::_queryVector( if (!parseResult.isOK()) { return parseResult.getStatus(); } - const std::unique_ptr<MatchExpression> matcher(parseResult.getValue()); + const std::unique_ptr<MatchExpression> matcher = std::move(parseResult.getValue()); NamespaceDocumentMap::iterator mapIt = _documents.find(collectionName); if (mapIt == _documents.end()) diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index 6cc86b5f4a9..3c9dfa8e940 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -237,8 +237,7 @@ Status Collection::checkValidation(OperationContext* txn, const BSONObj& documen return {ErrorCodes::DocumentValidationFailure, "Document failed validation"}; } -StatusWith<std::unique_ptr<MatchExpression>> Collection::parseValidator( - const BSONObj& validator) const { +StatusWithMatchExpression Collection::parseValidator(const BSONObj& validator) const { if (validator.isEmpty()) return {nullptr}; @@ -259,11 +258,11 @@ StatusWith<std::unique_ptr<MatchExpression>> Collection::parseValidator( return status; } - auto statusWithRawPtr = MatchExpressionParser::parse(validator); - if (!statusWithRawPtr.isOK()) - return statusWithRawPtr.getStatus(); + auto statusWithMatcher = MatchExpressionParser::parse(validator); + if (!statusWithMatcher.isOK()) + return statusWithMatcher.getStatus(); - return {std::unique_ptr<MatchExpression>(statusWithRawPtr.getValue())}; + return statusWithMatcher; } StatusWith<RecordId> Collection::insertDocument(OperationContext* txn, diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h index ca00e76ef57..4d40ecc698e 100644 --- a/src/mongo/db/catalog/collection.h +++ b/src/mongo/db/catalog/collection.h @@ -358,7 +358,7 @@ private: /** * Returns a non-ok Status if validator is not legal for this collection. */ - StatusWith<std::unique_ptr<MatchExpression>> parseValidator(const BSONObj& validator) const; + StatusWithMatchExpression parseValidator(const BSONObj& validator) const; Status recordStoreGoingToMove(OperationContext* txn, const RecordId& oldLocation, diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp index 85a1b8f401f..b1df971ac70 100644 --- a/src/mongo/db/catalog/index_catalog.cpp +++ b/src/mongo/db/catalog/index_catalog.cpp @@ -535,11 +535,12 @@ Status IndexCatalog::_isSpecOk(const BSONObj& spec) const { return Status(ErrorCodes::CannotCreateIndex, "'partialFilterExpression' for an index has to be a document"); } - StatusWithMatchExpression res = MatchExpressionParser::parse(filterElement.Obj()); - if (!res.isOK()) { - return res.getStatus(); + StatusWithMatchExpression statusWithMatcher = + MatchExpressionParser::parse(filterElement.Obj()); + if (!statusWithMatcher.isOK()) { + return statusWithMatcher.getStatus(); } - const std::unique_ptr<MatchExpression> filterExpr(res.getValue()); + const std::unique_ptr<MatchExpression> filterExpr = std::move(statusWithMatcher.getValue()); Status status = _checkValidFilterExpressions(filterExpr.get()); if (!status.isOK()) { diff --git a/src/mongo/db/catalog/index_catalog_entry.cpp b/src/mongo/db/catalog/index_catalog_entry.cpp index 55f5511680b..00d680c43c9 100644 --- a/src/mongo/db/catalog/index_catalog_entry.cpp +++ b/src/mongo/db/catalog/index_catalog_entry.cpp @@ -103,10 +103,10 @@ void IndexCatalogEntry::init(OperationContext* txn, IndexAccessMethod* accessMet if (filterElement.type()) { invariant(filterElement.isABSONObj()); BSONObj filter = filterElement.Obj(); - StatusWithMatchExpression res = MatchExpressionParser::parse(filter); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filter); // this should be checked in create, so can blow up here - invariantOK(res.getStatus()); - _filterExpression.reset(res.getValue()); + invariantOK(statusWithMatcher.getStatus()); + _filterExpression = std::move(statusWithMatcher.getValue()); LOG(2) << "have filter expression for " << _ns << " " << _descriptor->indexName() << " " << filter; } diff --git a/src/mongo/db/clientlistplugin.cpp b/src/mongo/db/clientlistplugin.cpp index 62676395328..66e15df4393 100644 --- a/src/mongo/db/clientlistplugin.cpp +++ b/src/mongo/db/clientlistplugin.cpp @@ -168,11 +168,12 @@ public: BSONObjBuilder& result) { unique_ptr<MatchExpression> filter; if (cmdObj["filter"].isABSONObj()) { - StatusWithMatchExpression res = MatchExpressionParser::parse(cmdObj["filter"].Obj()); - if (!res.isOK()) { - return appendCommandStatus(result, res.getStatus()); + StatusWithMatchExpression statusWithMatcher = + MatchExpressionParser::parse(cmdObj["filter"].Obj()); + if (!statusWithMatcher.isOK()) { + return appendCommandStatus(result, statusWithMatcher.getStatus()); } - filter.reset(res.getValue()); + filter = std::move(statusWithMatcher.getValue()); } result.appendArray("operations", diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index a5b12e97f9c..8fb6f063590 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -111,7 +111,7 @@ public: if (!statusWithMatcher.isOK()) { return appendCommandStatus(result, statusWithMatcher.getStatus()); } - matcher.reset(statusWithMatcher.getValue()); + matcher = std::move(statusWithMatcher.getValue()); } const long long defaultBatchSize = std::numeric_limits<long long>::max(); diff --git a/src/mongo/db/exec/projection_exec.cpp b/src/mongo/db/exec/projection_exec.cpp index 2ce77a120d6..ffde80dfbe1 100644 --- a/src/mongo/db/exec/projection_exec.cpp +++ b/src/mongo/db/exec/projection_exec.cpp @@ -113,11 +113,12 @@ ProjectionExec::ProjectionExec(const BSONObj& spec, BSONObj elemMatchObj = e.wrap(); verify(elemMatchObj.isOwned()); _elemMatchObjs.push_back(elemMatchObj); - StatusWithMatchExpression swme = + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(elemMatchObj, whereCallback); - verify(swme.isOK()); + verify(statusWithMatcher.isOK()); // And store it in _matchers. - _matchers[mongoutils::str::before(e.fieldName(), '.').c_str()] = swme.getValue(); + _matchers[mongoutils::str::before(e.fieldName(), '.').c_str()] = + statusWithMatcher.getValue().release(); add(e.fieldName(), true); } else if (mongoutils::str::equals(e2.fieldName(), "$meta")) { diff --git a/src/mongo/db/exec/projection_exec_test.cpp b/src/mongo/db/exec/projection_exec_test.cpp index 8575591e6d1..c3b2e37774d 100644 --- a/src/mongo/db/exec/projection_exec_test.cpp +++ b/src/mongo/db/exec/projection_exec_test.cpp @@ -47,11 +47,10 @@ using std::unique_ptr; /** * Utility function to create MatchExpression */ -MatchExpression* parseMatchExpression(const BSONObj& obj) { +unique_ptr<MatchExpression> parseMatchExpression(const BSONObj& obj) { StatusWithMatchExpression status = MatchExpressionParser::parse(obj); ASSERT_TRUE(status.isOK()); - MatchExpression* expr(status.getValue()); - return expr; + return std::move(status.getValue()); } // @@ -80,7 +79,7 @@ void testTransform(const char* specStr, // Create projection exec object. BSONObj spec = fromjson(specStr); BSONObj query = fromjson(queryStr); - unique_ptr<MatchExpression> queryExpression(parseMatchExpression(query)); + unique_ptr<MatchExpression> queryExpression = std::move(parseMatchExpression(query)); ProjectionExec exec(spec, queryExpression.get()); // Create working set member. diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp index a0188289c29..f7df5a8f2f6 100644 --- a/src/mongo/db/exec/stagedebug_cmd.cpp +++ b/src/mongo/db/exec/stagedebug_cmd.cpp @@ -230,13 +230,14 @@ public: } BSONObj argObj = e.Obj(); if (filterTag == e.fieldName()) { - StatusWithMatchExpression swme = MatchExpressionParser::parse( + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse( argObj, WhereCallbackReal(txn, collection->ns().db())); - if (!swme.isOK()) { + if (!statusWithMatcher.isOK()) { return NULL; } + std::unique_ptr<MatchExpression> me = std::move(statusWithMatcher.getValue()); // exprs is what will wind up deleting this. - matcher = swme.getValue(); + matcher = me.release(); verify(NULL != matcher); exprs->mutableVector().push_back(matcher); } else if (argsTag == e.fieldName()) { diff --git a/src/mongo/db/matcher/expression_algo_test.cpp b/src/mongo/db/matcher/expression_algo_test.cpp index a108a7a7f3b..9effbf6b0b9 100644 --- a/src/mongo/db/matcher/expression_algo_test.cpp +++ b/src/mongo/db/matcher/expression_algo_test.cpp @@ -49,7 +49,7 @@ public: ParsedMatchExpression(const std::string& str) : _obj(fromjson(str)) { StatusWithMatchExpression result = MatchExpressionParser::parse(_obj); ASSERT_OK(result.getStatus()); - _expr.reset(result.getValue()); + _expr = std::move(result.getValue()); } const MatchExpression* get() const { diff --git a/src/mongo/db/matcher/expression_parser.cpp b/src/mongo/db/matcher/expression_parser.cpp index e5fe8ec8cfc..2f27c157f9c 100644 --- a/src/mongo/db/matcher/expression_parser.cpp +++ b/src/mongo/db/matcher/expression_parser.cpp @@ -36,6 +36,7 @@ #include "mongo/db/matcher/expression_array.h" #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_tree.h" +#include "mongo/stdx/memory.h" #include "mongo/util/mongoutils/str.h" @@ -74,14 +75,14 @@ StatusWithMatchExpression MatchExpressionParser::_parseComparison(const char* na if (MatchExpression::EQ != cmp->matchType() && RegEx == e.type()) { std::stringstream ss; ss << "Can't have RegEx as arg to predicate over field '" << name << "'."; - return StatusWithMatchExpression(Status(ErrorCodes::BadValue, ss.str())); + return {Status(ErrorCodes::BadValue, ss.str())}; } Status s = temp->init(name, e); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; - return StatusWithMatchExpression(temp.release()); + return {std::move(temp)}; } StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& context, @@ -103,13 +104,11 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c case -1: // $where cannot be a sub-expression because it works on top-level documents only. if (mongoutils::str::equals("$where", e.fieldName())) { - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$where cannot be applied to a field"); + return {Status(ErrorCodes::BadValue, "$where cannot be applied to a field")}; } - return StatusWithMatchExpression(ErrorCodes::BadValue, - mongoutils::str::stream() - << "unknown operator: " << e.fieldName()); + return {Status(ErrorCodes::BadValue, + mongoutils::str::stream() << "unknown operator: " << e.fieldName())}; case BSONObj::LT: return _parseComparison(name, new LTMatchExpression(), e); case BSONObj::LTE: @@ -122,51 +121,50 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c if (RegEx == e.type()) { // Just because $ne can be rewritten as the negation of an // equality does not mean that $ne of a regex is allowed. See SERVER-1705. - return StatusWithMatchExpression( - Status(ErrorCodes::BadValue, "Can't have regex as arg to $ne.")); + return {Status(ErrorCodes::BadValue, "Can't have regex as arg to $ne.")}; } StatusWithMatchExpression s = _parseComparison(name, new EqualityMatchExpression(), e); if (!s.isOK()) return s; - std::unique_ptr<NotMatchExpression> n(new NotMatchExpression()); - Status s2 = n->init(s.getValue()); + std::unique_ptr<NotMatchExpression> n = stdx::make_unique<NotMatchExpression>(); + Status s2 = n->init(s.getValue().release()); if (!s2.isOK()) - return StatusWithMatchExpression(s2); - return StatusWithMatchExpression(n.release()); + return s2; + return {std::move(n)}; } case BSONObj::Equality: return _parseComparison(name, new EqualityMatchExpression(), e); case BSONObj::opIN: { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, "$in needs an array"); - std::unique_ptr<InMatchExpression> temp(new InMatchExpression()); + return {Status(ErrorCodes::BadValue, "$in needs an array")}; + std::unique_ptr<InMatchExpression> temp = stdx::make_unique<InMatchExpression>(); Status s = temp->init(name); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; s = _parseArrayFilterEntries(temp->getArrayFilterEntries(), e.Obj()); if (!s.isOK()) - return StatusWithMatchExpression(s); - return StatusWithMatchExpression(temp.release()); + return s; + return {std::move(temp)}; } case BSONObj::NIN: { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, "$nin needs an array"); - std::unique_ptr<InMatchExpression> temp(new InMatchExpression()); + return {Status(ErrorCodes::BadValue, "$nin needs an array")}; + std::unique_ptr<InMatchExpression> temp = stdx::make_unique<InMatchExpression>(); Status s = temp->init(name); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; s = _parseArrayFilterEntries(temp->getArrayFilterEntries(), e.Obj()); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; - std::unique_ptr<NotMatchExpression> temp2(new NotMatchExpression()); + std::unique_ptr<NotMatchExpression> temp2 = stdx::make_unique<NotMatchExpression>(); s = temp2->init(temp.release()); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; - return StatusWithMatchExpression(temp2.release()); + return {std::move(temp2)}; } case BSONObj::opSIZE: { @@ -191,30 +189,31 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c size = -1; } } else { - return StatusWithMatchExpression(ErrorCodes::BadValue, "$size needs a number"); + return {Status(ErrorCodes::BadValue, "$size needs a number")}; } - std::unique_ptr<SizeMatchExpression> temp(new SizeMatchExpression()); + std::unique_ptr<SizeMatchExpression> temp = stdx::make_unique<SizeMatchExpression>(); Status s = temp->init(name, size); if (!s.isOK()) - return StatusWithMatchExpression(s); - return StatusWithMatchExpression(temp.release()); + return s; + return {std::move(temp)}; } case BSONObj::opEXISTS: { if (e.eoo()) - return StatusWithMatchExpression(ErrorCodes::BadValue, "$exists can't be eoo"); - std::unique_ptr<ExistsMatchExpression> temp(new ExistsMatchExpression()); + return {Status(ErrorCodes::BadValue, "$exists can't be eoo")}; + std::unique_ptr<ExistsMatchExpression> temp = + stdx::make_unique<ExistsMatchExpression>(); Status s = temp->init(name); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; if (e.trueValue()) - return StatusWithMatchExpression(temp.release()); - std::unique_ptr<NotMatchExpression> temp2(new NotMatchExpression()); + return {std::move(temp)}; + std::unique_ptr<NotMatchExpression> temp2 = stdx::make_unique<NotMatchExpression>(); s = temp2->init(temp.release()); if (!s.isOK()) - return StatusWithMatchExpression(s); - return StatusWithMatchExpression(temp2.release()); + return s; + return {std::move(temp2)}; } case BSONObj::opTYPE: @@ -231,10 +230,10 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c while (i.more()) { BSONElement temp = i.next(); if (temp.getGtLtOp(-1) == BSONObj::opREGEX) - return StatusWithMatchExpression(NULL); + return {nullptr}; } - return StatusWithMatchExpression(ErrorCodes::BadValue, "$options needs a $regex"); + return {Status(ErrorCodes::BadValue, "$options needs a $regex")}; } case BSONObj::opREGEX: { @@ -252,8 +251,8 @@ StatusWithMatchExpression MatchExpressionParser::_parseSubField(const BSONObj& c return expressionParserGeoCallback(name, x, context); } - return StatusWithMatchExpression(ErrorCodes::BadValue, - mongoutils::str::stream() << "not handled: " << e.fieldName()); + return {Status(ErrorCodes::BadValue, + mongoutils::str::stream() << "not handled: " << e.fieldName())}; } StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, int level) { @@ -261,10 +260,10 @@ StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, int mongoutils::str::stream ss; ss << "exceeded maximum query tree depth of " << kMaximumTreeDepth << " at " << obj.toString(); - return StatusWithMatchExpression(ErrorCodes::BadValue, ss); + return {Status(ErrorCodes::BadValue, ss)}; } - std::unique_ptr<AndMatchExpression> root(new AndMatchExpression()); + std::unique_ptr<AndMatchExpression> root = stdx::make_unique<AndMatchExpression>(); bool topLevel = (level == 0); level++; @@ -278,64 +277,64 @@ StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, int // TODO: optimize if block? if (mongoutils::str::equals("or", rest)) { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, "$or needs an array"); - std::unique_ptr<OrMatchExpression> temp(new OrMatchExpression()); + return {Status(ErrorCodes::BadValue, "$or needs an array")}; + std::unique_ptr<OrMatchExpression> temp = stdx::make_unique<OrMatchExpression>(); Status s = _parseTreeList(e.Obj(), temp.get(), level); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; root->add(temp.release()); } else if (mongoutils::str::equals("and", rest)) { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, "and needs an array"); - std::unique_ptr<AndMatchExpression> temp(new AndMatchExpression()); + return {Status(ErrorCodes::BadValue, "and needs an array")}; + std::unique_ptr<AndMatchExpression> temp = stdx::make_unique<AndMatchExpression>(); Status s = _parseTreeList(e.Obj(), temp.get(), level); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; root->add(temp.release()); } else if (mongoutils::str::equals("nor", rest)) { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, "and needs an array"); - std::unique_ptr<NorMatchExpression> temp(new NorMatchExpression()); + return {Status(ErrorCodes::BadValue, "and needs an array")}; + std::unique_ptr<NorMatchExpression> temp = stdx::make_unique<NorMatchExpression>(); Status s = _parseTreeList(e.Obj(), temp.get(), level); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; root->add(temp.release()); } else if (mongoutils::str::equals("atomic", rest) || mongoutils::str::equals("isolated", rest)) { if (!topLevel) - return StatusWithMatchExpression( - ErrorCodes::BadValue, "$atomic/$isolated has to be at the top level"); + return {Status(ErrorCodes::BadValue, + "$atomic/$isolated has to be at the top level")}; if (e.trueValue()) root->add(new AtomicMatchExpression()); } else if (mongoutils::str::equals("where", rest)) { StatusWithMatchExpression s = _whereCallback->parseWhere(e); if (!s.isOK()) return s; - root->add(s.getValue()); + root->add(s.getValue().release()); } else if (mongoutils::str::equals("text", rest)) { if (e.type() != Object) { - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$text expects an object"); + return {Status(ErrorCodes::BadValue, "$text expects an object")}; } StatusWithMatchExpression s = expressionParserTextCallback(e.Obj()); if (!s.isOK()) { return s; } - root->add(s.getValue()); + root->add(s.getValue().release()); } else if (mongoutils::str::equals("comment", rest)) { } else if (mongoutils::str::equals("ref", rest) || mongoutils::str::equals("id", rest) || mongoutils::str::equals("db", rest)) { // DBRef fields. - std::unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); + std::unique_ptr<ComparisonMatchExpression> eq = + stdx::make_unique<EqualityMatchExpression>(); Status s = eq->init(e.fieldName(), e); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; root->add(eq.release()); } else { - return StatusWithMatchExpression( - ErrorCodes::BadValue, - mongoutils::str::stream() << "unknown top level operator: " << e.fieldName()); + return {Status(ErrorCodes::BadValue, + mongoutils::str::stream() + << "unknown top level operator: " << e.fieldName())}; } continue; @@ -344,7 +343,7 @@ StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, int if (_isExpressionDocument(e, false)) { Status s = _parseSub(e.fieldName(), e.Obj(), root.get(), level); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; continue; } @@ -352,25 +351,26 @@ StatusWithMatchExpression MatchExpressionParser::_parse(const BSONObj& obj, int StatusWithMatchExpression result = _parseRegexElement(e.fieldName(), e); if (!result.isOK()) return result; - root->add(result.getValue()); + root->add(result.getValue().release()); continue; } - std::unique_ptr<ComparisonMatchExpression> eq(new EqualityMatchExpression()); + std::unique_ptr<ComparisonMatchExpression> eq = + stdx::make_unique<EqualityMatchExpression>(); Status s = eq->init(e.fieldName(), e); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; root->add(eq.release()); } if (root->numChildren() == 1) { - const MatchExpression* real = root->getChild(0); + std::unique_ptr<MatchExpression> real(root->getChild(0)); root->clearAndRelease(); - return StatusWithMatchExpression(const_cast<MatchExpression*>(real)); + return {std::move(real)}; } - return StatusWithMatchExpression(root.release()); + return {std::move(root)}; } Status MatchExpressionParser::_parseSub(const char* name, @@ -407,7 +407,7 @@ Status MatchExpressionParser::_parseSub(const char* name, StatusWithMatchExpression s = expressionParserGeoCallback(name, firstElt.getGtLtOp(), sub); if (s.isOK()) { - root->add(s.getValue()); + root->add(s.getValue().release()); } // Propagate geo parsing result to caller. @@ -425,7 +425,7 @@ Status MatchExpressionParser::_parseSub(const char* name, return s.getStatus(); if (s.getValue()) - root->add(s.getValue()); + root->add(s.getValue().release()); } return Status::OK(); @@ -493,47 +493,42 @@ bool MatchExpressionParser::_isDBRefDocument(const BSONObj& obj, bool allowIncom StatusWithMatchExpression MatchExpressionParser::_parseMOD(const char* name, const BSONElement& e) { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, - "malformed mod, needs to be an array"); + return {Status(ErrorCodes::BadValue, "malformed mod, needs to be an array")}; BSONObjIterator i(e.Obj()); if (!i.more()) - return StatusWithMatchExpression(ErrorCodes::BadValue, - "malformed mod, not enough elements"); + return {Status(ErrorCodes::BadValue, "malformed mod, not enough elements")}; BSONElement d = i.next(); if (!d.isNumber()) - return StatusWithMatchExpression(ErrorCodes::BadValue, - "malformed mod, divisor not a number"); + return {Status(ErrorCodes::BadValue, "malformed mod, divisor not a number")}; if (!i.more()) - return StatusWithMatchExpression(ErrorCodes::BadValue, - "malformed mod, not enough elements"); + return {Status(ErrorCodes::BadValue, "malformed mod, not enough elements")}; BSONElement r = i.next(); if (!d.isNumber()) - return StatusWithMatchExpression(ErrorCodes::BadValue, - "malformed mod, remainder not a number"); + return {Status(ErrorCodes::BadValue, "malformed mod, remainder not a number")}; if (i.more()) - return StatusWithMatchExpression(ErrorCodes::BadValue, "malformed mod, too many elements"); + return {Status(ErrorCodes::BadValue, "malformed mod, too many elements")}; - std::unique_ptr<ModMatchExpression> temp(new ModMatchExpression()); + std::unique_ptr<ModMatchExpression> temp = stdx::make_unique<ModMatchExpression>(); Status s = temp->init(name, d.numberInt(), r.numberInt()); if (!s.isOK()) - return StatusWithMatchExpression(s); - return StatusWithMatchExpression(temp.release()); + return s; + return {std::move(temp)}; } StatusWithMatchExpression MatchExpressionParser::_parseRegexElement(const char* name, const BSONElement& e) { if (e.type() != RegEx) - return StatusWithMatchExpression(ErrorCodes::BadValue, "not a regex"); + return {Status(ErrorCodes::BadValue, "not a regex")}; - std::unique_ptr<RegexMatchExpression> temp(new RegexMatchExpression()); + std::unique_ptr<RegexMatchExpression> temp = stdx::make_unique<RegexMatchExpression>(); Status s = temp->init(name, e.regex(), e.regexFlags()); if (!s.isOK()) - return StatusWithMatchExpression(s); - return StatusWithMatchExpression(temp.release()); + return s; + return {std::move(temp)}; } StatusWithMatchExpression MatchExpressionParser::_parseRegexDocument(const char* name, @@ -552,15 +547,13 @@ StatusWithMatchExpression MatchExpressionParser::_parseRegexDocument(const char* regex = e.regex(); regexOptions = e.regexFlags(); } else { - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$regex has to be a string"); + return {Status(ErrorCodes::BadValue, "$regex has to be a string")}; } break; case BSONObj::opOPTIONS: if (e.type() != String) - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$options has to be a string"); + return {Status(ErrorCodes::BadValue, "$options has to be a string")}; regexOptions = e.String(); break; default: @@ -568,11 +561,11 @@ StatusWithMatchExpression MatchExpressionParser::_parseRegexDocument(const char* } } - std::unique_ptr<RegexMatchExpression> temp(new RegexMatchExpression()); + std::unique_ptr<RegexMatchExpression> temp = stdx::make_unique<RegexMatchExpression>(); Status s = temp->init(name, regex, regexOptions); if (!s.isOK()) - return StatusWithMatchExpression(s); - return StatusWithMatchExpression(temp.release()); + return s; + return {std::move(temp)}; } Status MatchExpressionParser::_parseArrayFilterEntries(ArrayFilterEntries* entries, @@ -587,7 +580,7 @@ Status MatchExpressionParser::_parseArrayFilterEntries(ArrayFilterEntries* entri } if (e.type() == RegEx) { - std::unique_ptr<RegexMatchExpression> r(new RegexMatchExpression()); + std::unique_ptr<RegexMatchExpression> r = stdx::make_unique<RegexMatchExpression>(); Status s = r->init("", e); if (!s.isOK()) return s; @@ -639,14 +632,14 @@ StatusWithMatchExpression MatchExpressionParser::_parseType(const char* name, return s; } - return temp.release(); + return {std::move(temp)}; } StatusWithMatchExpression MatchExpressionParser::_parseElemMatch(const char* name, const BSONElement& e, int level) { if (e.type() != Object) - return StatusWithMatchExpression(ErrorCodes::BadValue, "$elemMatch needs an Object"); + return {Status(ErrorCodes::BadValue, "$elemMatch needs an Object")}; BSONObj obj = e.Obj(); @@ -676,19 +669,20 @@ StatusWithMatchExpression MatchExpressionParser::_parseElemMatch(const char* nam AndMatchExpression theAnd; Status s = _parseSub("", obj, &theAnd, level); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; - std::unique_ptr<ElemMatchValueMatchExpression> temp(new ElemMatchValueMatchExpression()); + std::unique_ptr<ElemMatchValueMatchExpression> temp = + stdx::make_unique<ElemMatchValueMatchExpression>(); s = temp->init(name); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; for (size_t i = 0; i < theAnd.numChildren(); i++) { temp->add(theAnd.getChild(i)); } theAnd.clearAndRelease(); - return StatusWithMatchExpression(temp.release()); + return {std::move(temp)}; } // DBRef value case @@ -700,31 +694,31 @@ StatusWithMatchExpression MatchExpressionParser::_parseElemMatch(const char* nam StatusWithMatchExpression subRaw = _parse(obj, level); if (!subRaw.isOK()) return subRaw; - std::unique_ptr<MatchExpression> sub(subRaw.getValue()); + std::unique_ptr<MatchExpression> sub = std::move(subRaw.getValue()); // $where is not supported under $elemMatch because $where // applies to top-level document, not array elements in a field. if (hasNode(sub.get(), MatchExpression::WHERE)) { - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$elemMatch cannot contain $where expression"); + return {Status(ErrorCodes::BadValue, "$elemMatch cannot contain $where expression")}; } - std::unique_ptr<ElemMatchObjectMatchExpression> temp(new ElemMatchObjectMatchExpression()); + std::unique_ptr<ElemMatchObjectMatchExpression> temp = + stdx::make_unique<ElemMatchObjectMatchExpression>(); Status status = temp->init(name, sub.release()); if (!status.isOK()) - return StatusWithMatchExpression(status); + return status; - return StatusWithMatchExpression(temp.release()); + return {std::move(temp)}; } StatusWithMatchExpression MatchExpressionParser::_parseAll(const char* name, const BSONElement& e, int level) { if (e.type() != Array) - return StatusWithMatchExpression(ErrorCodes::BadValue, "$all needs an array"); + return {Status(ErrorCodes::BadValue, "$all needs an array")}; BSONObj arr = e.Obj(); - std::unique_ptr<AndMatchExpression> myAnd(new AndMatchExpression()); + std::unique_ptr<AndMatchExpression> myAnd = stdx::make_unique<AndMatchExpression>(); BSONObjIterator i(arr); if (arr.firstElement().type() == Object && @@ -737,73 +731,71 @@ StatusWithMatchExpression MatchExpressionParser::_parseAll(const char* name, if (hopefullyElemMatchElement.type() != Object) { // $all : [ { $elemMatch : ... }, 5 ] - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$all/$elemMatch has to be consistent"); + return {Status(ErrorCodes::BadValue, "$all/$elemMatch has to be consistent")}; } BSONObj hopefullyElemMatchObj = hopefullyElemMatchElement.Obj(); if (!mongoutils::str::equals("$elemMatch", hopefullyElemMatchObj.firstElement().fieldName())) { // $all : [ { $elemMatch : ... }, { x : 5 } ] - return StatusWithMatchExpression(ErrorCodes::BadValue, - "$all/$elemMatch has to be consistent"); + return {Status(ErrorCodes::BadValue, "$all/$elemMatch has to be consistent")}; } StatusWithMatchExpression inner = _parseElemMatch(name, hopefullyElemMatchObj.firstElement(), level); if (!inner.isOK()) return inner; - myAnd->add(inner.getValue()); + myAnd->add(inner.getValue().release()); } - return StatusWithMatchExpression(myAnd.release()); + return {std::move(myAnd)}; } while (i.more()) { BSONElement e = i.next(); if (e.type() == RegEx) { - std::unique_ptr<RegexMatchExpression> r(new RegexMatchExpression()); + std::unique_ptr<RegexMatchExpression> r = stdx::make_unique<RegexMatchExpression>(); Status s = r->init(name, e); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; myAnd->add(r.release()); } else if (e.type() == Object && e.Obj().firstElement().getGtLtOp(-1) != -1) { - return StatusWithMatchExpression(ErrorCodes::BadValue, "no $ expressions in $all"); + return {Status(ErrorCodes::BadValue, "no $ expressions in $all")}; } else { - std::unique_ptr<EqualityMatchExpression> x(new EqualityMatchExpression()); + std::unique_ptr<EqualityMatchExpression> x = + stdx::make_unique<EqualityMatchExpression>(); Status s = x->init(name, e); if (!s.isOK()) - return StatusWithMatchExpression(s); + return s; myAnd->add(x.release()); } } if (myAnd->numChildren() == 0) { - return StatusWithMatchExpression(new FalseMatchExpression()); + return {stdx::make_unique<FalseMatchExpression>()}; } - return StatusWithMatchExpression(myAnd.release()); + return {std::move(myAnd)}; } StatusWithMatchExpression MatchExpressionParser::WhereCallback::parseWhere( const BSONElement& where) const { - return StatusWithMatchExpression(ErrorCodes::NoWhereParseContext, - "no context for parsing $where"); + return {Status(ErrorCodes::NoWhereParseContext, "no context for parsing $where")}; } // Geo StatusWithMatchExpression expressionParserGeoCallbackDefault(const char* name, int type, const BSONObj& section) { - return StatusWithMatchExpression(ErrorCodes::BadValue, "geo not linked in"); + return {Status(ErrorCodes::BadValue, "geo not linked in")}; } MatchExpressionParserGeoCallback expressionParserGeoCallback = expressionParserGeoCallbackDefault; // Text StatusWithMatchExpression expressionParserTextCallbackDefault(const BSONObj& queryObj) { - return StatusWithMatchExpression(ErrorCodes::BadValue, "$text not linked in"); + return {Status(ErrorCodes::BadValue, "$text not linked in")}; } MatchExpressionParserTextCallback expressionParserTextCallback = diff --git a/src/mongo/db/matcher/expression_parser.h b/src/mongo/db/matcher/expression_parser.h index ea331467c2f..e9bb3cf7200 100644 --- a/src/mongo/db/matcher/expression_parser.h +++ b/src/mongo/db/matcher/expression_parser.h @@ -41,7 +41,7 @@ namespace mongo { class OperationContext; -typedef StatusWith<MatchExpression*> StatusWithMatchExpression; +typedef StatusWith<std::unique_ptr<MatchExpression>> StatusWithMatchExpression; class MatchExpressionParser { public: diff --git a/src/mongo/db/matcher/expression_parser_array_test.cpp b/src/mongo/db/matcher/expression_parser_array_test.cpp index 01bd6301d73..29da1ee21c3 100644 --- a/src/mongo/db/matcher/expression_parser_array_test.cpp +++ b/src/mongo/db/matcher/expression_parser_array_test.cpp @@ -50,7 +50,6 @@ TEST(MatchExpressionParserArrayTest, Size1) { ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2 << 3)))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, SizeAsString) { @@ -63,7 +62,6 @@ TEST(MatchExpressionParserArrayTest, SizeAsString) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSONArray()))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1)))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, SizeWithDouble) { @@ -76,7 +74,6 @@ TEST(MatchExpressionParserArrayTest, SizeWithDouble) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSONArray()))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2 << 3)))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, SizeBad) { @@ -96,7 +93,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchArr1) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1))))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1 << "y" << 2))))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, ElemMatchAnd) { @@ -109,7 +105,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchAnd) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1))))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1 << "y" << 2))))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, ElemMatchNor) { @@ -121,7 +116,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchNor) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1))))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 2 << "y" << 2))))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, ElemMatchOr) { @@ -134,7 +128,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchOr) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1))))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1 << "y" << 2))))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, ElemMatchVal1) { @@ -145,7 +138,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchVal1) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(4)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(6)))); - delete result.getValue(); } // with explicit $eq @@ -168,7 +160,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef1) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << match))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(notMatch)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(match)))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, ElemMatchDBRef2) { @@ -190,7 +181,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef2) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << match))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(notMatch)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(match)))); - delete result.getValue(); } // Additional fields after $ref and $id. @@ -217,7 +207,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef3) { BSON("x" << BSON_ARRAY(BSON("$ref" << "coll" << "$id" << oid << "foo" << 12345 << "bar" << 678))))); - delete result.getValue(); } // Query with DBRef fields out of order. @@ -244,7 +233,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef4) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << match))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(notMatch)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(match)))); - delete result.getValue(); } // Query with DBRef fields out of order. @@ -274,7 +262,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef5) { BSON("x" << BSON_ARRAY(BSON("$ref" << "coll" << "$id" << oid << "foo" << 12345 << "bar" << 678))))); - delete result.getValue(); } // Incomplete DBRef - $id missing. @@ -303,7 +290,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef6) { BSON("x" << BSON_ARRAY(BSON("$ref" << "coll" << "$id" << oid << "foo" << 12345 << "bar" << 678))))); - delete result.getValue(); } // Incomplete DBRef - $ref missing. @@ -331,7 +317,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef7) { BSON("x" << BSON_ARRAY(BSON("$ref" << "coll" << "$id" << oid << "foo" << 12345 << "bar" << 678))))); - delete result.getValue(); } // Incomplete DBRef - $db only. @@ -366,7 +351,6 @@ TEST(MatchExpressionParserArrayTest, ElemMatchDBRef8) { << "$id" << oid << "$db" << "db" << "foo" << 12345 << "bar" << 678))))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, All1) { @@ -383,7 +367,6 @@ TEST(MatchExpressionParserArrayTest, All1) { ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2 << 3)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(2 << 3)))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, AllNull) { @@ -398,7 +381,6 @@ TEST(MatchExpressionParserArrayTest, AllNull) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSONNULL))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONNULL)))); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, AllBadArg) { @@ -445,7 +427,6 @@ TEST(MatchExpressionParserArrayTest, AllRegex1) { ASSERT(!result.getValue()->matchesSingleElement(notMatchFirst["a"])); ASSERT(!result.getValue()->matchesSingleElement(notMatchSecond["a"])); ASSERT(result.getValue()->matchesSingleElement(matchesBoth["a"])); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, AllRegex2) { @@ -469,7 +450,6 @@ TEST(MatchExpressionParserArrayTest, AllRegex2) { ASSERT(!result.getValue()->matchesSingleElement(notMatchFirst["a"])); ASSERT(result.getValue()->matchesSingleElement(matchesBoth["a"])); - delete result.getValue(); } TEST(MatchExpressionParserArrayTest, AllNonArray) { @@ -484,7 +464,6 @@ TEST(MatchExpressionParserArrayTest, AllNonArray) { ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(5)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 4))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(4)))); - delete result.getValue(); } @@ -504,7 +483,6 @@ TEST(MatchExpressionParserArrayTest, AllElemMatch1) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(1 << 2)))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1))))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSON("x" << 1 << "y" << 2))))); - delete result.getValue(); } // $all and $elemMatch on dotted field. @@ -541,7 +519,6 @@ TEST(MatchExpressionParserArrayTest, AllElemMatch2) { // x is an array. ASSERT(result.getValue()->matchesBSON( BSON("x" << BSON_ARRAY(BSON("y" << BSON_ARRAY(BSON("x" << 1 << "z" << 1))))))); - delete result.getValue(); } // Check the structure of the resulting MatchExpression, and make sure that the paths @@ -551,7 +528,7 @@ TEST(MatchExpressionParserArrayTest, AllElemMatch3) { StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> expr(result.getValue()); + std::unique_ptr<MatchExpression> expr = std::move(result.getValue()); // Root node should be an AND with one child. ASSERT_EQUALS(MatchExpression::AND, expr->matchType()); @@ -629,7 +606,6 @@ TEST(MatchExpressionParserArrayTest, AllEmptyString) { << ""))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONNULL << "")))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONObj() << "")))); - delete result.getValue(); } // $all with ISO date. @@ -652,7 +628,6 @@ TEST(MatchExpressionParserArrayTest, AllISODate) { ASSERT(result.getValue()->matchesBSON(BSON("x" << match))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONNULL << match)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONObj() << match)))); - delete result.getValue(); } // $all on array element with empty string. @@ -672,7 +647,6 @@ TEST(MatchExpressionParserArrayTest, AllDottedEmptyString) { << ""))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONNULL << "")))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONObj() << "")))); - delete result.getValue(); } // $all on array element with ISO date. @@ -697,6 +671,5 @@ TEST(MatchExpressionParserArrayTest, AllDottedISODate) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << match))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONNULL << match)))); ASSERT(result.getValue()->matchesBSON(BSON("x" << BSON_ARRAY(BSONObj() << match)))); - delete result.getValue(); } } diff --git a/src/mongo/db/matcher/expression_parser_geo.cpp b/src/mongo/db/matcher/expression_parser_geo.cpp index f740a93abac..d706ef65193 100644 --- a/src/mongo/db/matcher/expression_parser_geo.cpp +++ b/src/mongo/db/matcher/expression_parser_geo.cpp @@ -33,23 +33,25 @@ #include "mongo/base/init.h" #include "mongo/db/jsobj.h" #include "mongo/db/matcher/expression_geo.h" +#include "mongo/stdx/memory.h" #include "mongo/util/mongoutils/str.h" namespace mongo { using std::unique_ptr; +using stdx::make_unique; StatusWithMatchExpression expressionParserGeoCallbackReal(const char* name, int type, const BSONObj& section) { if (BSONObj::opWITHIN == type || BSONObj::opGEO_INTERSECTS == type) { - unique_ptr<GeoExpression> gq(new GeoExpression(name)); + unique_ptr<GeoExpression> gq = make_unique<GeoExpression>(name); Status parseStatus = gq->parseFrom(section); if (!parseStatus.isOK()) return StatusWithMatchExpression(parseStatus); - unique_ptr<GeoMatchExpression> e(new GeoMatchExpression()); + unique_ptr<GeoMatchExpression> e = make_unique<GeoMatchExpression>(); // Until the index layer accepts non-BSON predicates, or special indices are moved into // stages, we have to clean up the raw object so it can be passed down to the index @@ -59,15 +61,15 @@ StatusWithMatchExpression expressionParserGeoCallbackReal(const char* name, Status s = e->init(name, gq.release(), bob.obj()); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(e.release()); + return {std::move(e)}; } else { verify(BSONObj::opNEAR == type); - unique_ptr<GeoNearExpression> nq(new GeoNearExpression(name)); + unique_ptr<GeoNearExpression> nq = make_unique<GeoNearExpression>(name); Status s = nq->parseFrom(section); if (!s.isOK()) { return StatusWithMatchExpression(s); } - unique_ptr<GeoNearMatchExpression> e(new GeoNearMatchExpression()); + unique_ptr<GeoNearMatchExpression> e = make_unique<GeoNearMatchExpression>(); // Until the index layer accepts non-BSON predicates, or special indices are moved into // stages, we have to clean up the raw object so it can be passed down to the index // layer. @@ -76,7 +78,7 @@ StatusWithMatchExpression expressionParserGeoCallbackReal(const char* name, s = e->init(name, nq.release(), bob.obj()); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(e.release()); + return {std::move(e)}; } } diff --git a/src/mongo/db/matcher/expression_parser_geo_test.cpp b/src/mongo/db/matcher/expression_parser_geo_test.cpp index f86366754a9..b280e54d208 100644 --- a/src/mongo/db/matcher/expression_parser_geo_test.cpp +++ b/src/mongo/db/matcher/expression_parser_geo_test.cpp @@ -44,7 +44,6 @@ TEST(MatchExpressionParserGeo, WithinBox) { StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(fromjson("{a: [3,4]}"))); ASSERT(result.getValue()->matchesBSON(fromjson("{a: [4,4]}"))); @@ -60,9 +59,8 @@ TEST(MatchExpressionParserGeoNear, ParseNear) { StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); - MatchExpression* exp = result.getValue(); + MatchExpression* exp = result.getValue().get(); ASSERT_EQUALS(MatchExpression::GEO_NEAR, exp->matchType()); GeoNearMatchExpression* gnexp = static_cast<GeoNearMatchExpression*>(exp); diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp index 1d8e7e0e8d8..47c239dfa01 100644 --- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp @@ -49,7 +49,6 @@ TEST(MatchExpressionParserLeafTest, SimpleEQ2) { BSONObj query = BSON("x" << BSON("$eq" << 2)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); @@ -66,7 +65,6 @@ TEST(MatchExpressionParserLeafTest, SimpleGT1) { BSONObj query = BSON("x" << BSON("$gt" << 2)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 3))); @@ -76,7 +74,6 @@ TEST(MatchExpressionParserLeafTest, SimpleLT1) { BSONObj query = BSON("x" << BSON("$lt" << 2)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2))); @@ -87,7 +84,6 @@ TEST(MatchExpressionParserLeafTest, SimpleGTE1) { BSONObj query = BSON("x" << BSON("$gte" << 2)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); @@ -98,7 +94,6 @@ TEST(MatchExpressionParserLeafTest, SimpleLTE1) { BSONObj query = BSON("x" << BSON("$lte" << 2)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); @@ -109,7 +104,6 @@ TEST(MatchExpressionParserLeafTest, SimpleNE1) { BSONObj query = BSON("x" << BSON("$ne" << 2)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2))); @@ -120,7 +114,6 @@ TEST(MatchExpressionParserLeafTest, SimpleModBad1) { BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy1(result.getValue()); query = BSON("x" << BSON("$mod" << BSON_ARRAY(3))); result = MatchExpressionParser::parse(query); @@ -147,7 +140,6 @@ TEST(MatchExpressionParserLeafTest, SimpleMod1) { BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 5))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 4))); @@ -158,7 +150,6 @@ TEST(MatchExpressionParserLeafTest, SimpleModNotNumber) { BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(2 << "r"))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 4))); @@ -172,7 +163,6 @@ TEST(MatchExpressionParserLeafTest, SimpleIN1) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(2 << 3))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); @@ -187,7 +177,6 @@ TEST(MatchExpressionParserLeafTest, INSingleDBRef) { << "db")))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); OID oidx = OID::gen(); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON("$ref" @@ -250,7 +239,6 @@ TEST(MatchExpressionParserLeafTest, INMultipleDBRef) { << "db")))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); OID oidx = OID::gen(); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON("$ref" @@ -350,7 +338,6 @@ TEST(MatchExpressionParserLeafTest, INDBRefWithOptionalField1) { << "$id" << oid << "foo" << 12345)))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); OID oidx = OID::gen(); ASSERT(!result.getValue()->matchesBSON(BSON("x" << BSON("$ref" @@ -452,7 +439,6 @@ TEST(MatchExpressionParserLeafTest, INRegexStuff) { BSONObj query = BSON("a" << operand.obj()); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); BSONObj matchFirst = BSON("a" << "ax"); @@ -478,7 +464,6 @@ TEST(MatchExpressionParserLeafTest, SimpleNIN1) { BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY(2 << 3))); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2))); @@ -498,7 +483,6 @@ TEST(MatchExpressionParserLeafTest, Regex1) { BSONObj query = b.obj(); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << "abc"))); @@ -515,7 +499,6 @@ TEST(MatchExpressionParserLeafTest, Regex2) { << "i")); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << "abc"))); @@ -533,7 +516,6 @@ TEST(MatchExpressionParserLeafTest, Regex3) { StatusWithMatchExpression result = MatchExpressionParser::parse(query); log() << "result: " << result.getStatus() << endl; ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << "abc"))); @@ -578,7 +560,6 @@ TEST(MatchExpressionParserLeafTest, ExistsYes1) { BSONObj query = BSON("x" << b.obj()); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << "abc"))); @@ -592,7 +573,6 @@ TEST(MatchExpressionParserLeafTest, ExistsNO1) { BSONObj query = BSON("x" << b.obj()); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << "abc"))); @@ -604,7 +584,6 @@ TEST(MatchExpressionParserLeafTest, Type1) { BSONObj query = BSON("x" << BSON("$type" << String)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << "abc"))); @@ -615,7 +594,6 @@ TEST(MatchExpressionParserLeafTest, Type2) { BSONObj query = BSON("x" << BSON("$type" << (double)NumberDouble)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 5.3))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5))); @@ -625,7 +603,6 @@ TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) { BSONObj query = BSON("x" << BSON("$type" << 1.5)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5.3))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5))); @@ -635,7 +612,6 @@ TEST(MatchExpressionParserLeafTest, TypeNull) { BSONObj query = BSON("x" << BSON("$type" << jstNULL)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSONObj())); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5))); @@ -650,7 +626,6 @@ TEST(MatchExpressionParserLeafTest, TypeBadType) { BSONObj query = BSON("x" << b.obj()); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - std::unique_ptr<MatchExpression> destroy(result.getValue()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5.3))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5))); @@ -663,12 +638,12 @@ TEST(MatchExpressionParserLeafTest, TypeBad) { } TEST(MatchExpressionParserLeafTest, TypeBadString) { - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: null}}"))); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: true}}"))); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: {}}}}"))); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: null}}")).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: true}}")).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: {}}}}")).getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse( - fromjson("{a: {$type: ObjectId('000000000000000000000000')}}"))); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: []}}"))); + fromjson("{a: {$type: ObjectId('000000000000000000000000')}}")).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: []}}")).getStatus()); } TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) { @@ -676,7 +651,7 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) { MatchExpressionParser::parse(fromjson("{a: {$type: 'double'}}")); ASSERT(typeNumberDouble.isOK()); TypeMatchExpression* tmeNumberDouble = - static_cast<TypeMatchExpression*>(typeNumberDouble.getValue()); + static_cast<TypeMatchExpression*>(typeNumberDouble.getValue().get()); ASSERT(tmeNumberDouble->getData() == NumberDouble); ASSERT_TRUE(tmeNumberDouble->matchesBSON(fromjson("{a: 5.4}"))); ASSERT_FALSE(tmeNumberDouble->matchesBSON(fromjson("{a: NumberInt(5)}"))); @@ -686,7 +661,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) { StatusWithMatchExpression typeNumberInt = MatchExpressionParser::parse(fromjson("{a: {$type: 'int'}}")); ASSERT(typeNumberInt.isOK()); - TypeMatchExpression* tmeNumberInt = static_cast<TypeMatchExpression*>(typeNumberInt.getValue()); + TypeMatchExpression* tmeNumberInt = + static_cast<TypeMatchExpression*>(typeNumberInt.getValue().get()); ASSERT(tmeNumberInt->getData() == NumberInt); ASSERT_TRUE(tmeNumberInt->matchesBSON(fromjson("{a: NumberInt(5)}"))); ASSERT_FALSE(tmeNumberInt->matchesBSON(fromjson("{a: 5.4}"))); @@ -697,7 +673,7 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumberLong) { MatchExpressionParser::parse(fromjson("{a: {$type: 'long'}}")); ASSERT(typeNumberLong.isOK()); TypeMatchExpression* tmeNumberLong = - static_cast<TypeMatchExpression*>(typeNumberLong.getValue()); + static_cast<TypeMatchExpression*>(typeNumberLong.getValue().get()); ASSERT(tmeNumberLong->getData() == NumberLong); ASSERT_TRUE(tmeNumberLong->matchesBSON(BSON("a" << static_cast<long long>(-1)))); ASSERT_FALSE(tmeNumberLong->matchesBSON(fromjson("{a: true}"))); @@ -707,7 +683,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameString) { StatusWithMatchExpression typeString = MatchExpressionParser::parse(fromjson("{a: {$type: 'string'}}")); ASSERT(typeString.isOK()); - TypeMatchExpression* tmeString = static_cast<TypeMatchExpression*>(typeString.getValue()); + TypeMatchExpression* tmeString = + static_cast<TypeMatchExpression*>(typeString.getValue().get()); ASSERT(tmeString->getData() == String); ASSERT_TRUE(tmeString->matchesBSON(fromjson("{a: 'hello world'}"))); ASSERT_FALSE(tmeString->matchesBSON(fromjson("{a: 5.4}"))); @@ -717,7 +694,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnamejstOID) { StatusWithMatchExpression typejstOID = MatchExpressionParser::parse(fromjson("{a: {$type: 'objectId'}}")); ASSERT(typejstOID.isOK()); - TypeMatchExpression* tmejstOID = static_cast<TypeMatchExpression*>(typejstOID.getValue()); + TypeMatchExpression* tmejstOID = + static_cast<TypeMatchExpression*>(typejstOID.getValue().get()); ASSERT(tmejstOID->getData() == jstOID); ASSERT_TRUE(tmejstOID->matchesBSON(fromjson("{a: ObjectId('000000000000000000000000')}"))); ASSERT_FALSE(tmejstOID->matchesBSON(fromjson("{a: 'hello world'}"))); @@ -727,7 +705,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnamejstNULL) { StatusWithMatchExpression typejstNULL = MatchExpressionParser::parse(fromjson("{a: {$type: 'null'}}")); ASSERT(typejstNULL.isOK()); - TypeMatchExpression* tmejstNULL = static_cast<TypeMatchExpression*>(typejstNULL.getValue()); + TypeMatchExpression* tmejstNULL = + static_cast<TypeMatchExpression*>(typejstNULL.getValue().get()); ASSERT(tmejstNULL->getData() == jstNULL); ASSERT_TRUE(tmejstNULL->matchesBSON(fromjson("{a: null}"))); ASSERT_FALSE(tmejstNULL->matchesBSON(fromjson("{a: true}"))); @@ -737,7 +716,7 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameBool) { StatusWithMatchExpression typeBool = MatchExpressionParser::parse(fromjson("{a: {$type: 'bool'}}")); ASSERT(typeBool.isOK()); - TypeMatchExpression* tmeBool = static_cast<TypeMatchExpression*>(typeBool.getValue()); + TypeMatchExpression* tmeBool = static_cast<TypeMatchExpression*>(typeBool.getValue().get()); ASSERT(tmeBool->getData() == Bool); ASSERT_TRUE(tmeBool->matchesBSON(fromjson("{a: true}"))); ASSERT_FALSE(tmeBool->matchesBSON(fromjson("{a: null}"))); @@ -747,7 +726,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameObject) { StatusWithMatchExpression typeObject = MatchExpressionParser::parse(fromjson("{a: {$type: 'object'}}")); ASSERT(typeObject.isOK()); - TypeMatchExpression* tmeObject = static_cast<TypeMatchExpression*>(typeObject.getValue()); + TypeMatchExpression* tmeObject = + static_cast<TypeMatchExpression*>(typeObject.getValue().get()); ASSERT(tmeObject->getData() == Object); ASSERT_TRUE(tmeObject->matchesBSON(fromjson("{a: {}}"))); ASSERT_FALSE(tmeObject->matchesBSON(fromjson("{a: []}"))); @@ -757,7 +737,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameArray) { StatusWithMatchExpression typeArray = MatchExpressionParser::parse(fromjson("{a: {$type: 'array'}}")); ASSERT(typeArray.isOK()); - TypeMatchExpression* tmeArray = static_cast<TypeMatchExpression*>(typeArray.getValue()); + TypeMatchExpression* tmeArray = + static_cast<TypeMatchExpression*>(typeArray.getValue().get()); ASSERT(tmeArray->getData() == Array); ASSERT_TRUE(tmeArray->matchesBSON(fromjson("{a: [[]]}"))); ASSERT_FALSE(tmeArray->matchesBSON(fromjson("{a: {}}"))); diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp index 5af0c7a2843..4927cd29229 100644 --- a/src/mongo/db/matcher/expression_parser_test.cpp +++ b/src/mongo/db/matcher/expression_parser_test.cpp @@ -46,8 +46,6 @@ TEST(MatchExpressionParserTest, SimpleEQ1) { ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 3))); - - delete result.getValue(); } TEST(MatchExpressionParserTest, Multiple1) { @@ -60,20 +58,16 @@ TEST(MatchExpressionParserTest, Multiple1) { ASSERT(!result.getValue()->matchesBSON(BSON("x" << 6 << "y" << 7))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5 << "y" << 9))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5 << "y" << 4))); - - delete result.getValue(); } TEST(AtomicMatchExpressionTest, Simple1) { BSONObj query = BSON("x" << 5 << "$atomic" << BSON("$gt" << 5 << "$lt" << 8)); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - delete result.getValue(); query = BSON("x" << 5 << "$isolated" << 1); result = MatchExpressionParser::parse(query); ASSERT_TRUE(result.isOK()); - delete result.getValue(); query = BSON("x" << 5 << "y" << BSON("$isolated" << 1)); result = MatchExpressionParser::parse(query); diff --git a/src/mongo/db/matcher/expression_parser_text.cpp b/src/mongo/db/matcher/expression_parser_text.cpp index de46f9e1169..a01529bee91 100644 --- a/src/mongo/db/matcher/expression_parser_text.cpp +++ b/src/mongo/db/matcher/expression_parser_text.cpp @@ -88,7 +88,7 @@ StatusWithMatchExpression expressionParserTextCallbackReal(const BSONObj& queryO if (!s.isOK()) { return StatusWithMatchExpression(s); } - return StatusWithMatchExpression(e.release()); + return {std::move(e)}; } MONGO_INITIALIZER(MatchExpressionParserText)(::mongo::InitializerContext* context) { diff --git a/src/mongo/db/matcher/expression_parser_text_test.cpp b/src/mongo/db/matcher/expression_parser_text_test.cpp index fe5eaebc0f7..33ab47af773 100644 --- a/src/mongo/db/matcher/expression_parser_text_test.cpp +++ b/src/mongo/db/matcher/expression_parser_text_test.cpp @@ -47,7 +47,7 @@ TEST(MatchExpressionParserText, Basic) { ASSERT_EQUALS(MatchExpression::TEXT, result.getValue()->matchType()); std::unique_ptr<TextMatchExpression> textExp( - static_cast<TextMatchExpression*>(result.getValue())); + static_cast<TextMatchExpression*>(result.getValue().release())); ASSERT_EQUALS(textExp->getQuery(), "awesome"); ASSERT_EQUALS(textExp->getLanguage(), "english"); ASSERT_EQUALS(textExp->getCaseSensitive(), fts::FTSQuery::caseSensitiveDefault); @@ -68,7 +68,7 @@ TEST(MatchExpressionParserText, CaseSensitiveTrue) { ASSERT_EQUALS(MatchExpression::TEXT, result.getValue()->matchType()); std::unique_ptr<TextMatchExpression> textExp( - static_cast<TextMatchExpression*>(result.getValue())); + static_cast<TextMatchExpression*>(result.getValue().release())); ASSERT_EQUALS(textExp->getCaseSensitive(), true); } @@ -80,7 +80,7 @@ TEST(MatchExpressionParserText, CaseSensitiveFalse) { ASSERT_EQUALS(MatchExpression::TEXT, result.getValue()->matchType()); std::unique_ptr<TextMatchExpression> textExp( - static_cast<TextMatchExpression*>(result.getValue())); + static_cast<TextMatchExpression*>(result.getValue().release())); ASSERT_EQUALS(textExp->getCaseSensitive(), false); } diff --git a/src/mongo/db/matcher/expression_parser_tree.cpp b/src/mongo/db/matcher/expression_parser_tree.cpp index 9a3149a8c5e..26ad561e756 100644 --- a/src/mongo/db/matcher/expression_parser_tree.cpp +++ b/src/mongo/db/matcher/expression_parser_tree.cpp @@ -35,6 +35,7 @@ #include "mongo/db/matcher/expression_array.h" #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_tree.h" +#include "mongo/stdx/memory.h" #include "mongo/util/mongoutils/str.h" namespace mongo { @@ -59,7 +60,7 @@ Status MatchExpressionParser::_parseTreeList(const BSONObj& arr, if (!sub.isOK()) return sub.getStatus(); - out->add(sub.getValue()); + out->add(sub.getValue().release()); } return Status::OK(); } @@ -71,11 +72,11 @@ StatusWithMatchExpression MatchExpressionParser::_parseNot(const char* name, StatusWithMatchExpression s = _parseRegexElement(name, e); if (!s.isOK()) return s; - std::unique_ptr<NotMatchExpression> n(new NotMatchExpression()); - Status s2 = n->init(s.getValue()); + std::unique_ptr<NotMatchExpression> n = stdx::make_unique<NotMatchExpression>(); + Status s2 = n->init(s.getValue().release()); if (!s2.isOK()) return StatusWithMatchExpression(s2); - return StatusWithMatchExpression(n.release()); + return {std::move(n)}; } if (e.type() != Object) @@ -85,7 +86,7 @@ StatusWithMatchExpression MatchExpressionParser::_parseNot(const char* name, if (notObject.isEmpty()) return StatusWithMatchExpression(ErrorCodes::BadValue, "$not cannot be empty"); - std::unique_ptr<AndMatchExpression> theAnd(new AndMatchExpression()); + std::unique_ptr<AndMatchExpression> theAnd = stdx::make_unique<AndMatchExpression>(); Status s = _parseSub(name, notObject, theAnd.get(), level); if (!s.isOK()) return StatusWithMatchExpression(s); @@ -96,11 +97,11 @@ StatusWithMatchExpression MatchExpressionParser::_parseNot(const char* name, if (theAnd->getChild(i)->matchType() == MatchExpression::REGEX) return StatusWithMatchExpression(ErrorCodes::BadValue, "$not cannot have a regex"); - std::unique_ptr<NotMatchExpression> theNot(new NotMatchExpression()); + std::unique_ptr<NotMatchExpression> theNot = stdx::make_unique<NotMatchExpression>(); s = theNot->init(theAnd.release()); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(theNot.release()); + return {std::move(theNot)}; } } diff --git a/src/mongo/db/matcher/expression_parser_tree_test.cpp b/src/mongo/db/matcher/expression_parser_tree_test.cpp index a650803d283..6e4530a1a29 100644 --- a/src/mongo/db/matcher/expression_parser_tree_test.cpp +++ b/src/mongo/db/matcher/expression_parser_tree_test.cpp @@ -48,8 +48,6 @@ TEST(MatchExpressionParserTreeTest, OR1) { ASSERT(result.getValue()->matchesBSON(BSON("y" << 2))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 3))); ASSERT(!result.getValue()->matchesBSON(BSON("y" << 1))); - - delete result.getValue(); } TEST(MatchExpressionParserTreeTest, OREmbedded) { @@ -62,8 +60,6 @@ TEST(MatchExpressionParserTreeTest, OREmbedded) { ASSERT(result.getValue()->matchesBSON(BSON("y" << 2))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 3))); ASSERT(!result.getValue()->matchesBSON(BSON("y" << 1))); - - delete result.getValue(); } @@ -78,8 +74,6 @@ TEST(MatchExpressionParserTreeTest, AND1) { ASSERT(!result.getValue()->matchesBSON(BSON("y" << 1))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1 << "y" << 2))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2 << "y" << 2))); - - delete result.getValue(); } TEST(MatchExpressionParserTreeTest, NOREmbedded) { @@ -91,8 +85,6 @@ TEST(MatchExpressionParserTreeTest, NOREmbedded) { ASSERT(!result.getValue()->matchesBSON(BSON("y" << 2))); ASSERT(result.getValue()->matchesBSON(BSON("x" << 3))); ASSERT(result.getValue()->matchesBSON(BSON("y" << 1))); - - delete result.getValue(); } TEST(MatchExpressionParserTreeTest, NOT1) { @@ -102,8 +94,6 @@ TEST(MatchExpressionParserTreeTest, NOT1) { ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 8))); - - delete result.getValue(); } // Test a deep match tree that is not deep enough to hit the maximum depth limit. @@ -122,7 +112,6 @@ TEST(MatchExpressionParserTreeTest, MaximumTreeDepthNotExceed) { BSONObj query = fromjson(ss.str()); StatusWithMatchExpression result = MatchExpressionParser::parse(query); ASSERT(result.isOK()); - delete result.getValue(); } // Test a tree that exceeds the maximum depth limit. @@ -193,7 +182,5 @@ TEST(MatchExpressionParserLeafTest, NotRegex1) { << "ABC"))); ASSERT(result.getValue()->matchesBSON(BSON("x" << "AC"))); - - delete result.getValue(); } } diff --git a/src/mongo/db/matcher/expression_where.cpp b/src/mongo/db/matcher/expression_where.cpp index 22985eb10e4..21c276a10b6 100644 --- a/src/mongo/db/matcher/expression_where.cpp +++ b/src/mongo/db/matcher/expression_where.cpp @@ -189,7 +189,7 @@ StatusWithMatchExpression WhereCallbackReal::parseWhere(const BSONElement& where Status s = exp->init(_dbName, where.valuestr(), BSONObj()); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(exp.release()); + return {std::move(exp)}; } if (where.type() == CodeWScope) { @@ -197,7 +197,7 @@ StatusWithMatchExpression WhereCallbackReal::parseWhere(const BSONElement& where exp->init(_dbName, where.codeWScopeCode(), BSONObj(where.codeWScopeScopeDataUnsafe())); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(exp.release()); + return {std::move(exp)}; } return StatusWithMatchExpression(ErrorCodes::BadValue, "$where got bad type"); diff --git a/src/mongo/db/matcher/expression_where_noop.cpp b/src/mongo/db/matcher/expression_where_noop.cpp index fcda8d6a006..a9db9b0413b 100644 --- a/src/mongo/db/matcher/expression_where_noop.cpp +++ b/src/mongo/db/matcher/expression_where_noop.cpp @@ -123,14 +123,14 @@ StatusWithMatchExpression WhereCallbackNoop::parseWhere(const BSONElement& where Status s = exp->init(where.valuestr()); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(exp.release()); + return {std::move(exp)}; } if (where.type() == CodeWScope) { Status s = exp->init(where.codeWScopeCode()); if (!s.isOK()) return StatusWithMatchExpression(s); - return StatusWithMatchExpression(exp.release()); + return {std::move(exp)}; } return StatusWithMatchExpression(ErrorCodes::BadValue, "$where got bad type"); diff --git a/src/mongo/db/matcher/matcher.cpp b/src/mongo/db/matcher/matcher.cpp index da7e68e2f09..df9a7fe71e1 100644 --- a/src/mongo/db/matcher/matcher.cpp +++ b/src/mongo/db/matcher/matcher.cpp @@ -43,12 +43,13 @@ namespace mongo { Matcher::Matcher(const BSONObj& pattern, const MatchExpressionParser::WhereCallback& whereCallback) : _pattern(pattern) { - StatusWithMatchExpression result = MatchExpressionParser::parse(pattern, whereCallback); + StatusWithMatchExpression statusWithMatcher = + MatchExpressionParser::parse(pattern, whereCallback); uassert(16810, - mongoutils::str::stream() << "bad query: " << result.getStatus().toString(), - result.isOK()); + mongoutils::str::stream() << "bad query: " << statusWithMatcher.getStatus().toString(), + statusWithMatcher.isOK()); - _expression.reset(result.getValue()); + _expression = std::move(statusWithMatcher.getValue()); } bool Matcher::matches(const BSONObj& doc, MatchDetails* details) const { diff --git a/src/mongo/db/ops/modifier_pull.cpp b/src/mongo/db/ops/modifier_pull.cpp index 3b45064afc7..b644c87d12d 100644 --- a/src/mongo/db/ops/modifier_pull.cpp +++ b/src/mongo/db/ops/modifier_pull.cpp @@ -119,10 +119,11 @@ Status ModifierPull::init(const BSONElement& modExpr, const Options& opts, bool* // $pull operations to contain $where clauses, so preserving this behaviour. StatusWithMatchExpression parseResult = MatchExpressionParser::parse(_exprObj, MatchExpressionParser::WhereCallback()); - if (!parseResult.isOK()) + if (!parseResult.isOK()) { return parseResult.getStatus(); + } - _matchExpr.reset(parseResult.getValue()); + _matchExpr = std::move(parseResult.getValue()); } return Status::OK(); diff --git a/src/mongo/db/ops/path_support_test.cpp b/src/mongo/db/ops/path_support_test.cpp index d3969c54fb1..bca8c35d604 100644 --- a/src/mongo/db/ops/path_support_test.cpp +++ b/src/mongo/db/ops/path_support_test.cpp @@ -491,7 +491,7 @@ TEST_F(ArrayDoc, NonNumericPathInArray) { static MatchExpression* makeExpr(const BSONObj& exprBSON) { static const WhereCallbackNoop callbackNoop; - return MatchExpressionParser::parse(exprBSON, callbackNoop).getValue(); + return MatchExpressionParser::parse(exprBSON, callbackNoop).getValue().release(); } static void assertContains(const EqualityMatches& equalities, const BSONObj& wrapped) { diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp index 145b65e0fad..e9cbd0153bd 100644 --- a/src/mongo/db/query/canonical_query.cpp +++ b/src/mongo/db/query/canonical_query.cpp @@ -212,17 +212,17 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( std::unique_ptr<LiteParsedQuery> autoLpq(lpq); // Make MatchExpression. - StatusWithMatchExpression swme = + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(autoLpq->getFilter(), whereCallback); - if (!swme.isOK()) { - return swme.getStatus(); + if (!statusWithMatcher.isOK()) { + return statusWithMatcher.getStatus(); } + std::unique_ptr<MatchExpression> me = std::move(statusWithMatcher.getValue()); // Make the CQ we'll hopefully return. std::unique_ptr<CanonicalQuery> cq(new CanonicalQuery()); - // Takes ownership of lpq and the MatchExpression* in swme. - Status initStatus = cq->init(autoLpq.release(), whereCallback, swme.getValue()); + Status initStatus = cq->init(autoLpq.release(), whereCallback, me.release()); if (!initStatus.isOK()) { return initStatus; @@ -303,15 +303,16 @@ StatusWith<std::unique_ptr<CanonicalQuery>> CanonicalQuery::canonicalize( auto& lpq = lpqStatus.getValue(); // Build a parse tree from the BSONObj in the parsed query. - StatusWithMatchExpression swme = MatchExpressionParser::parse(lpq->getFilter(), whereCallback); - if (!swme.isOK()) { - return swme.getStatus(); + StatusWithMatchExpression statusWithMatcher = + MatchExpressionParser::parse(lpq->getFilter(), whereCallback); + if (!statusWithMatcher.isOK()) { + return statusWithMatcher.getStatus(); } + std::unique_ptr<MatchExpression> me = std::move(statusWithMatcher.getValue()); // Make the CQ we'll hopefully return. std::unique_ptr<CanonicalQuery> cq(new CanonicalQuery()); - // Takes ownership of lpq and the MatchExpression* in swme. - Status initStatus = cq->init(lpq.release(), whereCallback, swme.getValue()); + Status initStatus = cq->init(lpq.release(), whereCallback, me.release()); if (!initStatus.isOK()) { return initStatus; diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp index e88a7442b3e..35f3976afdf 100644 --- a/src/mongo/db/query/canonical_query_test.cpp +++ b/src/mongo/db/query/canonical_query_test.cpp @@ -53,7 +53,7 @@ MatchExpression* parseMatchExpression(const BSONObj& obj) { FAIL(ss); } - return status.getValue(); + return status.getValue().release(); } /** diff --git a/src/mongo/db/query/index_bounds_builder_test.cpp b/src/mongo/db/query/index_bounds_builder_test.cpp index cf8129c016d..90a509a2577 100644 --- a/src/mongo/db/query/index_bounds_builder_test.cpp +++ b/src/mongo/db/query/index_bounds_builder_test.cpp @@ -58,7 +58,7 @@ double positiveInfinity = numeric_limits<double>::infinity(); MatchExpression* parseMatchExpression(const BSONObj& obj) { StatusWithMatchExpression status = MatchExpressionParser::parse(obj); ASSERT_TRUE(status.isOK()); - MatchExpression* expr(status.getValue()); + MatchExpression* expr(status.getValue().release()); return expr; } diff --git a/src/mongo/db/query/parsed_projection.cpp b/src/mongo/db/query/parsed_projection.cpp index 4ebcff2d1a3..6c01b0b3434 100644 --- a/src/mongo/db/query/parsed_projection.cpp +++ b/src/mongo/db/query/parsed_projection.cpp @@ -129,12 +129,11 @@ Status ParsedProjection::make(const BSONObj& spec, verify(elemMatchObj.isOwned()); // TODO: Is there a faster way of validating the elemMatchObj? - StatusWithMatchExpression swme = + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(elemMatchObj, whereCallback); - if (!swme.isOK()) { - return swme.getStatus(); + if (!statusWithMatcher.isOK()) { + return statusWithMatcher.getStatus(); } - delete swme.getValue(); } else if (mongoutils::str::equals(e2.fieldName(), "$meta")) { // Field for meta must be top level. We can relax this at some point. if (mongoutils::str::contains(e.fieldName(), '.')) { diff --git a/src/mongo/db/query/parsed_projection_test.cpp b/src/mongo/db/query/parsed_projection_test.cpp index 9128575ea95..4db3ebebe48 100644 --- a/src/mongo/db/query/parsed_projection_test.cpp +++ b/src/mongo/db/query/parsed_projection_test.cpp @@ -46,9 +46,9 @@ using namespace mongo; // unique_ptr<ParsedProjection> createParsedProjection(const BSONObj& query, const BSONObj& projObj) { - StatusWithMatchExpression swme = MatchExpressionParser::parse(query); - ASSERT(swme.isOK()); - std::unique_ptr<MatchExpression> queryMatchExpr(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(query); + ASSERT(statusWithMatcher.isOK()); + std::unique_ptr<MatchExpression> queryMatchExpr = std::move(statusWithMatcher.getValue()); ParsedProjection* out = NULL; Status status = ParsedProjection::make(projObj, queryMatchExpr.get(), &out); if (!status.isOK()) { @@ -72,9 +72,9 @@ unique_ptr<ParsedProjection> createParsedProjection(const char* queryStr, const void assertInvalidProjection(const char* queryStr, const char* projStr) { BSONObj query = fromjson(queryStr); BSONObj projObj = fromjson(projStr); - StatusWithMatchExpression swme = MatchExpressionParser::parse(query); - ASSERT(swme.isOK()); - std::unique_ptr<MatchExpression> queryMatchExpr(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(query); + ASSERT(statusWithMatcher.isOK()); + std::unique_ptr<MatchExpression> queryMatchExpr = std::move(statusWithMatcher.getValue()); ParsedProjection* out = NULL; Status status = ParsedProjection::make(projObj, queryMatchExpr.get(), &out); std::unique_ptr<ParsedProjection> destroy(out); diff --git a/src/mongo/db/query/plan_cache_indexability_test.cpp b/src/mongo/db/query/plan_cache_indexability_test.cpp index a5a0ca38e89..c1bdd0964e9 100644 --- a/src/mongo/db/query/plan_cache_indexability_test.cpp +++ b/src/mongo/db/query/plan_cache_indexability_test.cpp @@ -40,7 +40,7 @@ std::unique_ptr<MatchExpression> parseMatchExpression(const BSONObj& obj) { FAIL(str::stream() << "failed to parse query: " << obj.toString() << ". Reason: " << status.getStatus().toString()); } - return std::unique_ptr<MatchExpression>(status.getValue()); + return std::move(status.getValue()); } // Test sparse index discriminators for a simple sparse index. diff --git a/src/mongo/db/query/plan_cache_test.cpp b/src/mongo/db/query/plan_cache_test.cpp index 2bee0f5f10b..867f5261d6d 100644 --- a/src/mongo/db/query/plan_cache_test.cpp +++ b/src/mongo/db/query/plan_cache_test.cpp @@ -135,7 +135,7 @@ unique_ptr<CanonicalQuery> canonicalize(const char* queryStr, /** * Utility function to create MatchExpression */ -MatchExpression* parseMatchExpression(const BSONObj& obj) { +unique_ptr<MatchExpression> parseMatchExpression(const BSONObj& obj) { StatusWithMatchExpression status = MatchExpressionParser::parse(obj); if (!status.isOK()) { str::stream ss; @@ -143,8 +143,8 @@ MatchExpression* parseMatchExpression(const BSONObj& obj) { << ". Reason: " << status.getStatus().toString(); FAIL(ss); } - MatchExpression* expr(status.getValue()); - return expr; + + return std::move(status.getValue()); } void assertEquivalent(const char* queryStr, diff --git a/src/mongo/db/query/planner_ixselect_test.cpp b/src/mongo/db/query/planner_ixselect_test.cpp index 555a9db11ea..3271f2b9b2a 100644 --- a/src/mongo/db/query/planner_ixselect_test.cpp +++ b/src/mongo/db/query/planner_ixselect_test.cpp @@ -50,11 +50,10 @@ using std::vector; /** * Utility function to create MatchExpression */ -MatchExpression* parseMatchExpression(const BSONObj& obj) { +unique_ptr<MatchExpression> parseMatchExpression(const BSONObj& obj) { StatusWithMatchExpression status = MatchExpressionParser::parse(obj); ASSERT_TRUE(status.isOK()); - MatchExpression* expr(status.getValue()); - return expr; + return std::move(status.getValue()); } /** diff --git a/src/mongo/db/query/query_planner_test_fixture.cpp b/src/mongo/db/query/query_planner_test_fixture.cpp index 5f70ab0de64..aaedb200d83 100644 --- a/src/mongo/db/query/query_planner_test_fixture.cpp +++ b/src/mongo/db/query/query_planner_test_fixture.cpp @@ -340,7 +340,7 @@ std::unique_ptr<MatchExpression> QueryPlannerTest::parseMatchExpression(const BS FAIL(str::stream() << "failed to parse query: " << obj.toString() << ". Reason: " << status.getStatus().toString()); } - return std::unique_ptr<MatchExpression>(status.getValue()); + return std::move(status.getValue()); } } // namespace mongo diff --git a/src/mongo/db/query/query_planner_test_lib.cpp b/src/mongo/db/query/query_planner_test_lib.cpp index 6ff080a767f..d509c1973bc 100644 --- a/src/mongo/db/query/query_planner_test_lib.cpp +++ b/src/mongo/db/query/query_planner_test_lib.cpp @@ -51,11 +51,11 @@ bool filterMatches(const BSONObj& testFilter, const QuerySolutionNode* trueFilte if (NULL == trueFilterNode->filter) { return false; } - StatusWithMatchExpression swme = MatchExpressionParser::parse(testFilter); - if (!swme.isOK()) { + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(testFilter); + if (!statusWithMatcher.isOK()) { return false; } - const std::unique_ptr<MatchExpression> root(swme.getValue()); + const std::unique_ptr<MatchExpression> root = std::move(statusWithMatcher.getValue()); CanonicalQuery::sortTree(root.get()); std::unique_ptr<MatchExpression> trueFilter(trueFilterNode->filter->shallowClone()); CanonicalQuery::sortTree(trueFilter.get()); diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp index bd9efe25fd0..04e889da587 100644 --- a/src/mongo/dbtests/query_multi_plan_runner.cpp +++ b/src/mongo/dbtests/query_multi_plan_runner.cpp @@ -146,9 +146,9 @@ public: // Make the filter. BSONObj filterObj = BSON("foo" << 7); - StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj); - verify(swme.isOK()); - unique_ptr<MatchExpression> filter(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj); + verify(statusWithMatcher.isOK()); + unique_ptr<MatchExpression> filter = std::move(statusWithMatcher.getValue()); // Make the stage. unique_ptr<PlanStage> secondRoot( new CollectionScan(&_txn, csparams, sharedWs.get(), filter.get())); diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index 84593bc62f0..33341c12b5e 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -88,9 +88,9 @@ public: params.tailable = false; // Make the filter. - StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj); - verify(swme.isOK()); - unique_ptr<MatchExpression> filterExpr(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj); + verify(statusWithMatcher.isOK()); + unique_ptr<MatchExpression> filterExpr = std::move(statusWithMatcher.getValue()); // Make a scan and have the runner own it. unique_ptr<WorkingSet> ws = make_unique<WorkingSet>(); diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp index 652747bc482..82952021dca 100644 --- a/src/mongo/dbtests/query_stage_count.cpp +++ b/src/mongo/dbtests/query_stage_count.cpp @@ -140,8 +140,10 @@ public: unique_ptr<WorkingSet> ws(new WorkingSet); - StatusWithMatchExpression swme = MatchExpressionParser::parse(request.getQuery()); - unique_ptr<MatchExpression> expression(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = + MatchExpressionParser::parse(request.getQuery()); + ASSERT(statusWithMatcher.isOK()); + unique_ptr<MatchExpression> expression = std::move(statusWithMatcher.getValue()); PlanStage* scan; if (indexed) { diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp index 3b7443faaf7..f7a255ba482 100644 --- a/src/mongo/dbtests/query_stage_fetch.cpp +++ b/src/mongo/dbtests/query_stage_fetch.cpp @@ -190,9 +190,9 @@ public: // Make the filter. BSONObj filterObj = BSON("foo" << 6); - StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj); - verify(swme.isOK()); - unique_ptr<MatchExpression> filterExpr(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj); + verify(statusWithMatcher.isOK()); + unique_ptr<MatchExpression> filterExpr = std::move(statusWithMatcher.getValue()); // Matcher requires that foo==6 but we only have data with foo==5. unique_ptr<FetchStage> fetchStage( diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp index 73dc9e9f23e..6898293f858 100644 --- a/src/mongo/dbtests/query_stage_tests.cpp +++ b/src/mongo/dbtests/query_stage_tests.cpp @@ -77,9 +77,9 @@ public: int countResults(const IndexScanParams& params, BSONObj filterObj = BSONObj()) { AutoGetCollectionForRead ctx(&_txn, ns()); - StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj); - verify(swme.isOK()); - unique_ptr<MatchExpression> filterExpr(swme.getValue()); + StatusWithMatchExpression statusWithMatcher = MatchExpressionParser::parse(filterObj); + verify(statusWithMatcher.isOK()); + unique_ptr<MatchExpression> filterExpr = std::move(statusWithMatcher.getValue()); unique_ptr<WorkingSet> ws = stdx::make_unique<WorkingSet>(); unique_ptr<IndexScan> ix = |