From 5273c2bad7df58c44afdd677609b8656f399a906 Mon Sep 17 00:00:00 2001 From: James Wahlin Date: Wed, 5 Apr 2017 09:59:54 -0400 Subject: SERVER-28651 Move agg var ownership to ExpressionContext --- src/mongo/db/pipeline/document_source_redact.cpp | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/mongo/db/pipeline/document_source_redact.cpp') diff --git a/src/mongo/db/pipeline/document_source_redact.cpp b/src/mongo/db/pipeline/document_source_redact.cpp index ae79729f2e0..738a55cc056 100644 --- a/src/mongo/db/pipeline/document_source_redact.cpp +++ b/src/mongo/db/pipeline/document_source_redact.cpp @@ -63,8 +63,9 @@ static const Value keepVal = Value("keep"_sd); DocumentSource::GetNextResult DocumentSourceRedact::getNext() { auto nextInput = pSource->getNext(); for (; nextInput.isAdvanced(); nextInput = pSource->getNext()) { - _variables->setRoot(nextInput.getDocument()); - _variables->setValue(_currentId, Value(nextInput.releaseDocument())); + auto& variables = pExpCtx->variables; + variables.setRoot(nextInput.getDocument()); + variables.setValue(_currentId, Value(nextInput.releaseDocument())); if (boost::optional result = redactObject()) { return std::move(*result); } @@ -99,7 +100,7 @@ Pipeline::SourceContainer::iterator DocumentSourceRedact::doOptimizeAt( Value DocumentSourceRedact::redactValue(const Value& in) { const BSONType valueType = in.getType(); if (valueType == Object) { - _variables->setValue(_currentId, in); + pExpCtx->variables.setValue(_currentId, in); const boost::optional result = redactObject(); if (result) { return Value(*result); @@ -127,22 +128,23 @@ Value DocumentSourceRedact::redactValue(const Value& in) { } boost::optional DocumentSourceRedact::redactObject() { - const Value expressionResult = _expression->evaluate(_variables.get()); + auto& variables = pExpCtx->variables; + const Value expressionResult = _expression->evaluate(); ValueComparator simpleValueCmp; if (simpleValueCmp.evaluate(expressionResult == keepVal)) { - return _variables->getDocument(_currentId); + return variables.getDocument(_currentId); } else if (simpleValueCmp.evaluate(expressionResult == pruneVal)) { return boost::optional(); } else if (simpleValueCmp.evaluate(expressionResult == descendVal)) { - const Document in = _variables->getDocument(_currentId); + const Document in = variables.getDocument(_currentId); MutableDocument out; out.copyMetaDataFrom(in); FieldIterator fields(in); while (fields.more()) { const Document::FieldPair field(fields.next()); - // This changes CURRENT so don't read from _variables after this + // This changes CURRENT so don't read from variables after this const Value val = redactValue(field.second); if (!val.missing()) { out.addField(field.first, val); @@ -169,8 +171,7 @@ Value DocumentSourceRedact::serialize(boost::optional intrusive_ptr DocumentSourceRedact::createFromBson( BSONElement elem, const intrusive_ptr& expCtx) { - VariablesIdGenerator idGenerator; - VariablesParseState vps(&idGenerator); + VariablesParseState vps = expCtx->variablesParseState; Variables::Id currentId = vps.defineVariable("CURRENT"); // will differ from ROOT Variables::Id decendId = vps.defineVariable("DESCEND"); Variables::Id pruneId = vps.defineVariable("PRUNE"); @@ -181,10 +182,10 @@ intrusive_ptr DocumentSourceRedact::createFromBson( // TODO figure out how much of this belongs in constructor and how much here. // Set up variables. Never need to reset DESCEND, PRUNE, or KEEP. source->_currentId = currentId; - source->_variables.reset(new Variables(idGenerator.getIdCount())); - source->_variables->setValue(decendId, descendVal); - source->_variables->setValue(pruneId, pruneVal); - source->_variables->setValue(keepId, keepVal); + auto& variables = expCtx->variables; + variables.setValue(decendId, descendVal); + variables.setValue(pruneId, pruneVal); + variables.setValue(keepId, keepVal); return source; -- cgit v1.2.1