diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-03-28 19:16:07 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-03-28 19:16:07 +0000 |
commit | c466e8c1ead9455b215572c8a1cfb29f87ab0ac7 (patch) | |
tree | 0fdffa25f4915bd729fe6eba72bce1185ac037a8 | |
parent | 6d0c1ef644e99f8a8d3835be4c61f28a8b887276 (diff) |
Remember the attribute, so you do not need to look it up again.
-rw-r--r-- | searchlib/src/vespa/searchlib/features/dotproductfeature.cpp | 28 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/features/dotproductfeature.h | 8 |
2 files changed, 19 insertions, 17 deletions
diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp index 153d44ea720..38842b1da53 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.cpp @@ -27,7 +27,7 @@ template <typename DimensionVType, typename DimensionHType, typename ComponentTy VectorBase<DimensionVType, DimensionHType, ComponentType, HashMapComparator>::VectorBase() { } template <typename DimensionVType, typename DimensionHType, typename ComponentType, typename HashMapComparator> -VectorBase<DimensionVType, DimensionHType, ComponentType, HashMapComparator>::~VectorBase() { } +VectorBase<DimensionVType, DimensionHType, ComponentType, HashMapComparator>::~VectorBase() = default; template <typename V> V copyAndSync(const V & v) { @@ -101,7 +101,7 @@ DotProductExecutor<A>::DotProductExecutor(const A * attribute, const V & queryVe } template <typename A> -DotProductExecutor<A>::~DotProductExecutor() { } +DotProductExecutor<A>::~DotProductExecutor() = default; template <typename A> size_t @@ -119,7 +119,7 @@ SparseDotProductExecutor<A>::SparseDotProductExecutor(const A * attribute, const } template <typename A> -SparseDotProductExecutor<A>::~SparseDotProductExecutor() { } +SparseDotProductExecutor<A>::~SparseDotProductExecutor() = default; template <typename A> size_t @@ -143,7 +143,7 @@ DotProductByCopyExecutor<A>::DotProductByCopyExecutor(const A * attribute, const } template <typename A> -DotProductByCopyExecutor<A>::~DotProductByCopyExecutor() { } +DotProductByCopyExecutor<A>::~DotProductByCopyExecutor() = default; template <typename A> size_t @@ -166,7 +166,7 @@ SparseDotProductByCopyExecutor<A>::SparseDotProductByCopyExecutor(const A * attr } template <typename A> -SparseDotProductByCopyExecutor<A>::~SparseDotProductByCopyExecutor() { } +SparseDotProductByCopyExecutor<A>::~SparseDotProductByCopyExecutor() = default; template <typename A> size_t @@ -197,8 +197,7 @@ DotProductByContentFillExecutor<BaseType>::DotProductByContentFillExecutor( } template <typename BaseType> -DotProductByContentFillExecutor<BaseType>::~DotProductByContentFillExecutor() { -} +DotProductByContentFillExecutor<BaseType>::~DotProductByContentFillExecutor() = default; namespace { @@ -239,8 +238,7 @@ SparseDotProductByContentFillExecutor<BaseType>::SparseDotProductByContentFillEx } template <typename BaseType> -SparseDotProductByContentFillExecutor<BaseType>::~SparseDotProductByContentFillExecutor() { -} +SparseDotProductByContentFillExecutor<BaseType>::~SparseDotProductByContentFillExecutor() = default; template <typename BaseType> size_t SparseDotProductByContentFillExecutor<BaseType>::getAttributeValues(uint32_t docid, const AT * & values) { @@ -266,10 +264,11 @@ size_t SparseDotProductByContentFillExecutor<BaseType>::getAttributeValues(uint3 DotProductBlueprint::DotProductBlueprint() : Blueprint("dotProduct"), _defaultAttribute(), - _queryVector() + _queryVector(), + _attribute(nullptr) { } -DotProductBlueprint::~DotProductBlueprint() {} +DotProductBlueprint::~DotProductBlueprint() = default; vespalib::string DotProductBlueprint::getAttribute(const IQueryEnvironment & env) const @@ -305,7 +304,7 @@ DotProductBlueprint::getDescriptions() const { Blueprint::UP DotProductBlueprint::createInstance() const { - return Blueprint::UP(new DotProductBlueprint()); + return std::make_unique<DotProductBlueprint>(); } namespace { @@ -616,7 +615,8 @@ fef::Anything::UP attemptParseArrayQueryVector(const IAttributeVector & attribut void DotProductBlueprint::prepareSharedState(const IQueryEnvironment & env, IObjectStore & store) const { - const IAttributeVector * attribute = env.getAttributeContext().getAttribute(getAttribute(env)); + _attribute = env.getAttributeContext().getAttribute(getAttribute(env)); + const IAttributeVector * attribute = _attribute; if (attribute != nullptr) { if ((attribute->getCollectionType() == attribute::CollectionType::WSET) && attribute->hasEnum() && @@ -654,7 +654,7 @@ DotProductBlueprint::prepareSharedState(const IQueryEnvironment & env, IObjectSt FeatureExecutor & DotProductBlueprint::createExecutor(const IQueryEnvironment & env, vespalib::Stash &stash) const { - const IAttributeVector * attribute = env.getAttributeContext().getAttribute(getAttribute(env)); + const IAttributeVector * attribute = (_attribute != nullptr) ? _attribute : env.getAttributeContext().getAttribute(getAttribute(env)); if (attribute == nullptr) { LOG(warning, "The attribute vector '%s' was not found in the attribute manager, returning executor with default value.", getAttribute(env).c_str()); diff --git a/searchlib/src/vespa/searchlib/features/dotproductfeature.h b/searchlib/src/vespa/searchlib/features/dotproductfeature.h index 9356fe9c7f2..b6107a1a271 100644 --- a/searchlib/src/vespa/searchlib/features/dotproductfeature.h +++ b/searchlib/src/vespa/searchlib/features/dotproductfeature.h @@ -91,9 +91,9 @@ public: **/ class EnumVector : public VectorBase<search::attribute::EnumHandle, search::attribute::EnumHandle, feature_t> { private: - const search::attribute::IAttributeVector * _attribute; + const attribute::IAttributeVector * _attribute; public: - EnumVector(const search::attribute::IAttributeVector * attribute) : _attribute(attribute) {} + EnumVector(const attribute::IAttributeVector * attribute) : _attribute(attribute) {} void insert(vespalib::stringref label, vespalib::stringref value) { search::attribute::EnumHandle e; if (_attribute->findEnum(label.data(), e)) { @@ -115,7 +115,7 @@ private: Buffer _buffer; public: - DotProductExecutor(const search::attribute::IAttributeVector * attribute, const Vector & queryVector); + DotProductExecutor(const attribute::IAttributeVector * attribute, const Vector & queryVector); void execute(uint32_t docId) override; }; @@ -263,6 +263,8 @@ private: vespalib::string _defaultAttribute; vespalib::string _queryVector; + mutable const attribute::IAttributeVector * _attribute; + vespalib::string getAttribute(const fef::IQueryEnvironment & env) const; public: |