diff options
author | Geir Storli <geirst@verizonmedia.com> | 2020-05-11 15:08:46 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2020-05-11 15:08:46 +0000 |
commit | f3e1ce23ef1d3bd0c3313b8d546bced7af60a087 (patch) | |
tree | e00b2e9cb52072866522c6f4accb5febcb870b94 /searchcore | |
parent | d6e059759286443da0e30abb9212baf3b8c281ab (diff) |
Use std::make_unique and auto.
Diffstat (limited to 'searchcore')
6 files changed, 32 insertions, 31 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_explorer.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_explorer.cpp index ce1a5093294..4268e12d4e6 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_explorer.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_explorer.cpp @@ -37,9 +37,9 @@ AttributeManagerExplorer::get_children_names() const std::unique_ptr<vespalib::StateExplorer> AttributeManagerExplorer::get_child(vespalib::stringref name) const { - ExclusiveAttributeReadAccessor::UP attr = _mgr->getExclusiveReadAccessor(name); + auto attr = _mgr->getExclusiveReadAccessor(name); if (attr.get() != nullptr) { - return std::unique_ptr<vespalib::StateExplorer>(new AttributeVectorExplorer(std::move(attr))); + return std::make_unique<AttributeVectorExplorer>(std::move(attr)); } return std::unique_ptr<vespalib::StateExplorer>(); } diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp index 214db2c2d13..319ae2dcad1 100644 --- a/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/attribute/attributemanager.cpp @@ -146,7 +146,7 @@ AttributeManager::addAttribute(const AttributeWrap &attribute, const ShrinkerSP AttributeVector::SP AttributeManager::findAttribute(const vespalib::string &name) const { - AttributeMap::const_iterator itr = _attributes.find(name); + auto itr = _attributes.find(name); return (itr != _attributes.end()) ? itr->second.getAttribute() : AttributeVector::SP(); @@ -155,7 +155,7 @@ AttributeManager::findAttribute(const vespalib::string &name) const const AttributeManager::FlushableWrap * AttributeManager::findFlushable(const vespalib::string &name) const { - FlushableMap::const_iterator itr = _flushables.find(name); + auto itr = _flushables.find(name); return (itr != _flushables.end()) ? &itr->second : nullptr; } @@ -232,7 +232,7 @@ AttributeManager::AttributeManager(const vespalib::string &baseDir, _documentSubDbName(documentSubDbName), _tuneFileAttributes(tuneFileAttributes), _fileHeaderContext(fileHeaderContext), - _factory(new AttributeFactory()), + _factory(std::make_shared<AttributeFactory>()), _interlock(std::make_shared<search::attribute::Interlock>()), _attributeFieldWriter(attributeFieldWriter), _hwInfo(hwInfo), @@ -369,15 +369,16 @@ AttributeManager::padAttribute(AttributeVector &v, uint32_t docIdLimit) v.commit(); } } - if (needCommit > 1) + if (needCommit > 1) { v.commit(); + } assert(v.getNumDocs() >= docIdLimit); } AttributeGuard::UP AttributeManager::getAttribute(const vespalib::string &name) const { - return AttributeGuard::UP(new AttributeGuard(findAttribute(name))); + return std::make_unique<AttributeGuard>(findAttribute(name)); } std::unique_ptr<search::attribute::AttributeReadGuard> @@ -540,7 +541,7 @@ AttributeManager::getAttributeFieldWriter() const AttributeVector * AttributeManager::getWritableAttribute(const vespalib::string &name) const { - AttributeMap::const_iterator itr = _attributes.find(name); + auto itr = _attributes.find(name); if (itr == _attributes.end() || itr->second.isExtra()) { return nullptr; } @@ -570,7 +571,7 @@ AttributeManager::asyncForEachAttribute(std::shared_ptr<IConstAttributeFunctor> void AttributeManager::asyncForAttribute(const vespalib::string &name, std::unique_ptr<IAttributeFunctor> func) const { - AttributeMap::const_iterator itr = _attributes.find(name); + auto itr = _attributes.find(name); if (itr == _attributes.end() || itr->second.isExtra() || !func) { return; } diff --git a/searchcore/src/vespa/searchcore/proton/bucketdb/bucketdb.cpp b/searchcore/src/vespa/searchcore/proton/bucketdb/bucketdb.cpp index e80543368d4..47cfef239fa 100644 --- a/searchcore/src/vespa/searchcore/proton/bucketdb/bucketdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/bucketdb/bucketdb.cpp @@ -224,8 +224,8 @@ BucketDB::populateActiveBuckets(const BucketId::List &buckets, BucketId::List &f BIV sorted(buckets); BIV toAdd; std::sort(sorted.begin(), sorted.end()); - BIV::const_iterator si(sorted.begin()); - BIV::const_iterator se(sorted.end()); + auto si = sorted.begin(); + auto se = sorted.end(); for (const auto & entry : _map) { for (; si != se && !(entry.first < *si); ++si) { if (*si < entry.first) { diff --git a/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp b/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp index e762ac527f0..cb147878147 100644 --- a/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp +++ b/searchcore/src/vespa/searchcore/proton/common/handlermap.hpp @@ -85,7 +85,7 @@ public: "Handler is null for docType '%s'", docTypeNameVer.toString().c_str())); } - iterator it = _handlers.find(docTypeNameVer); + auto it = _handlers.find(docTypeNameVer); if (it == _handlers.end()) { _handlers[docTypeNameVer] = handler; return HandlerSP(); @@ -105,7 +105,7 @@ public: HandlerSP getHandler(const DocTypeName &docTypeNameVer) const { - const_iterator it = _handlers.find(docTypeNameVer); + auto it = _handlers.find(docTypeNameVer); if (it != _handlers.end()) { return it->second; } @@ -122,7 +122,7 @@ public: T * getHandlerPtr(const DocTypeName &docTypeNameVer) const { - const_iterator it = _handlers.find(docTypeNameVer); + auto it = _handlers.find(docTypeNameVer); return (it != _handlers.end()) ? it->second.get() : nullptr; } @@ -147,7 +147,7 @@ public: HandlerSP removeHandler(const DocTypeName &docTypeNameVer) { - iterator it = _handlers.find(docTypeNameVer); + auto it = _handlers.find(docTypeNameVer); if (it == _handlers.end()) { return HandlerSP(); } diff --git a/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp b/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp index 2c237074907..21c05137ad5 100644 --- a/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/selectpruner.cpp @@ -179,9 +179,9 @@ SelectPruner::visitAndBranch(const And &expr) rhs._node->setParentheses(); } if (_inverted) { - _node.reset(new Or(std::move(lhs._node), std::move(rhs._node), "or")); + _node = std::make_unique<Or>(std::move(lhs._node), std::move(rhs._node), "or"); } else { - _node.reset(new And(std::move(lhs._node), std::move(rhs._node), "and")); + _node = std::make_unique<And>(std::move(lhs._node), std::move(rhs._node), "and"); } addNodeCount(lhs); addNodeCount(rhs); @@ -205,10 +205,10 @@ SelectPruner::visitComparison(const Compare &expr) bool lhsNullVal = lhs.isNullVal(); bool rhsNullVal = rhs.isNullVal(); const Operator &op(getOperator(expr.getOperator())); - _node.reset(new Compare(std::move(lhs._valueNode), - op, - std::move(rhs._valueNode), - expr.getBucketIdFactory())); + _node = std::make_unique<Compare>(std::move(lhs._valueNode), + op, + std::move(rhs._valueNode), + expr.getBucketIdFactory()); _priority = ComparePriority; if (_constVal && (lhsNullVal || rhsNullVal)) { if (!lhsNullVal || !rhsNullVal) { @@ -243,7 +243,7 @@ SelectPruner::visitDocumentType(const DocType &expr) _inverted = true; res = !res; } - _node.reset(new Constant(res)); + _node = std::make_unique<Constant>(res); _resultSet.add(res ? Result::True : Result::False); _priority = DocumentTypePriority; } @@ -338,9 +338,9 @@ SelectPruner::visitOrBranch(const Or &expr) rhs._node->setParentheses(); } if (_inverted) { - _node.reset(new And(std::move(lhs._node), std::move(rhs._node), "and")); + _node = std::make_unique<And>(std::move(lhs._node), std::move(rhs._node), "and"); } else { - _node.reset(new Or(std::move(lhs._node), std::move(rhs._node), "or")); + _node = std::make_unique<Or>(std::move(lhs._node), std::move(rhs._node), "or"); } addNodeCount(lhs); addNodeCount(rhs); @@ -375,7 +375,7 @@ SelectPruner::visitFunctionValueNode(const FunctionValueNode &expr) } ValueNode::UP child(std::move(_valueNode)); const vespalib::string &funcName(expr.getFunctionName()); - _valueNode.reset(new FunctionValueNode(funcName, std::move(child))); + _valueNode = std::make_unique<FunctionValueNode>(funcName, std::move(child)); if (_priority < FuncPriority) { _valueNode->setParentheses(); } @@ -406,7 +406,7 @@ SelectPruner::visitFieldValueNode(const FieldValueNode &expr) const bool is_imported = docType->has_imported_field_name(name); if (complex || !is_imported) { try { - std::unique_ptr<Field> fp(new Field(docType->getField(name))); + auto fp = std::make_unique<Field>(docType->getField(name)); if (!fp) { setInvalidVal(); return; @@ -476,7 +476,7 @@ SelectPruner::invertNode() _node->setParentheses(); } NodeUP node(std::move(_node)); - _node.reset(new Not(std::move(node), "not")); + _node = std::make_unique<Not>(std::move(node), "not"); _priority = NotPriority; _inverted = !_inverted; } @@ -529,7 +529,7 @@ SelectPruner::setInvalidVal() { _constVal = true; _priority = InvalidValPriority; - _valueNode.reset(new InvalidValueNode("invalidval")); + _valueNode = std::make_unique<InvalidValueNode>("invalidval"); } @@ -538,7 +538,7 @@ SelectPruner::setInvalidConst() { _constVal = true; _priority = InvalidConstPriority; - _node.reset(new InvalidConstant("invalid")); + _node = std::make_unique<InvalidConstant>("invalid"); } void @@ -554,7 +554,7 @@ SelectPruner::setTernaryConst(bool val) { _constVal = true; _priority = ConstPriority; - _node.reset(new Constant(val)); + _node = std::make_unique<Constant>(val); } void diff --git a/searchcore/src/vespa/searchcore/proton/common/statusreport.h b/searchcore/src/vespa/searchcore/proton/common/statusreport.h index ddf81eb53cf..c7d36cb4759 100644 --- a/searchcore/src/vespa/searchcore/proton/common/statusreport.h +++ b/searchcore/src/vespa/searchcore/proton/common/statusreport.h @@ -69,7 +69,7 @@ public: ~StatusReport(); static StatusReport::UP create(const Params ¶ms) { - return StatusReport::UP(new StatusReport(params)); + return std::make_unique<StatusReport>(params); } const vespalib::string &getComponent() const { |