diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-08-26 19:20:25 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2022-08-26 19:33:37 +0200 |
commit | 98e28fe63cbb1bb1555121d6b3d04257e5fc183f (patch) | |
tree | dfec8c791335459a7c5dcca18a0f95d421182931 /searchsummary/src | |
parent | 7bf97a82b6a7efb54d48bc6ebfa41bf7b74f8ad7 (diff) |
Use more smart pointers in DynamicDocsumConfig, ResultConfig and KeywordExtractor.
Diffstat (limited to 'searchsummary/src')
6 files changed, 26 insertions, 60 deletions
diff --git a/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.cpp b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.cpp index da31e338036..2dc04c03845 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.cpp @@ -2,8 +2,6 @@ #include "copy_dfw.h" #include "i_docsum_store_document.h" -#include "resultclass.h" -#include "resultconfig.h" #include <vespa/vespalib/data/slime/slime.h> #include <vespa/log/log.h> @@ -11,27 +9,13 @@ LOG_SETUP(".searchlib.docsummary.copy_dfw"); namespace search::docsummary { -CopyDFW::CopyDFW() - : _inputFieldEnumValue(static_cast<uint32_t>(-1)), - _input_field_name() +CopyDFW::CopyDFW(const vespalib::string& inputField) + : _input_field_name(inputField) { } CopyDFW::~CopyDFW() = default; -bool -CopyDFW::Init(const ResultConfig & config, const char *inputField) -{ - _inputFieldEnumValue = config.GetFieldNameEnum().Lookup(inputField); - _input_field_name = inputField; - - if (_inputFieldEnumValue >= config.GetFieldNameEnum().GetNumEntries()) { - LOG(warning, "no docsum format contains field '%s'; copied fields will be empty", inputField); - } - - return true; -} - void CopyDFW::insertField(uint32_t, const IDocsumStoreDocument* doc, GetDocsumsState *, ResType, vespalib::slime::Inserter &target) const diff --git a/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h index 91cf2c91bb8..fb2b7315945 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/copy_dfw.h @@ -14,15 +14,12 @@ class ResultConfig; class CopyDFW : public DocsumFieldWriter { private: - uint32_t _inputFieldEnumValue; vespalib::string _input_field_name; public: - CopyDFW(); + CopyDFW(const vespalib::string& inputField); ~CopyDFW() override; - bool Init(const ResultConfig & config, const char *inputField); - bool IsGenerated() const override { return false; } void insertField(uint32_t docid, const IDocsumStoreDocument* doc, GetDocsumsState *state, ResType type, vespalib::slime::Inserter &target) const override; diff --git a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp index c4090044e18..8dbd35af36e 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/docsumconfig.cpp @@ -36,9 +36,10 @@ DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string & if (overrideName == "dynamicteaser") { if ( ! argument.empty() ) { const char *langFieldName = "something unused"; - DynamicTeaserDFW *fw = new DynamicTeaserDFW(getEnvironment()->getJuniper()); - fieldWriter.reset(fw); - rc = fw->Init(fieldName.c_str(), langFieldName, resultConfig, argument.c_str()); + auto fw = std::make_unique<DynamicTeaserDFW>(getEnvironment()->getJuniper()); + auto fw_ptr = fw.get(); + fieldWriter = std::move(fw); + rc = fw_ptr->Init(fieldName.c_str(), langFieldName, resultConfig, argument.c_str()); } else { throw IllegalArgumentException("Missing argument"); } @@ -53,9 +54,8 @@ DynamicDocsumConfig::createFieldWriter(const string & fieldName, const string & rc = true; } else if (overrideName == "copy") { if ( ! argument.empty() ) { - CopyDFW *fw = new CopyDFW(); - fieldWriter.reset(fw); - rc = fw->Init(resultConfig, argument.c_str()); + fieldWriter = std::make_unique<CopyDFW>(argument); + rc = true; } else { throw IllegalArgumentException("Missing argument"); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp b/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp index 19f6a7eef01..ba4833c912a 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.cpp @@ -19,7 +19,7 @@ bool useful(search::ParseItem::ItemCreator creator) KeywordExtractor::KeywordExtractor(IDocsumEnvironment * env) : _env(env), - _legalPrefixes(nullptr), + _legalPrefixes(), _legalIndexes() { } @@ -27,11 +27,6 @@ KeywordExtractor::KeywordExtractor(IDocsumEnvironment * env) KeywordExtractor::~KeywordExtractor() { - while (_legalPrefixes != nullptr) { - IndexPrefix *tmp = _legalPrefixes; - _legalPrefixes = tmp->_next; - delete tmp; - } } bool @@ -40,12 +35,9 @@ KeywordExtractor::IsLegalIndexName(const char *idxName) const return _legalIndexes.find(idxName) != _legalIndexes.end(); } -KeywordExtractor::IndexPrefix::IndexPrefix(const char *prefix, IndexPrefix **list) - : _prefix(prefix), - _next(nullptr) +KeywordExtractor::IndexPrefix::IndexPrefix(const char *prefix) + : _prefix(prefix) { - _next = *list; - *list = this; } KeywordExtractor::IndexPrefix::~IndexPrefix() = default; @@ -99,12 +91,12 @@ KeywordExtractor::GetLegalIndexSpec() { vespalib::string spec; - if (_legalPrefixes != nullptr) { - for (IndexPrefix *pt = _legalPrefixes; - pt != nullptr; pt = pt->_next) { - if (spec.size() > 0) + if (!_legalPrefixes.empty()) { + for (auto& prefix : _legalPrefixes) { + if (!spec.empty()) { spec.append(';'); - spec.append(pt->_prefix); + } + spec.append(prefix.get_prefix()); spec.append('*'); } } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.h b/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.h index 44c85121058..e1cea6d1032 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.h +++ b/searchsummary/src/vespa/searchsummary/docsummary/keywordextractor.h @@ -19,33 +19,27 @@ public: class IndexPrefix { - private: - IndexPrefix(const IndexPrefix &); - IndexPrefix& operator=(const IndexPrefix &); - - public: vespalib::string _prefix; - IndexPrefix *_next; + public: - IndexPrefix(const char *prefix, IndexPrefix **list); + IndexPrefix(const char *prefix); ~IndexPrefix(); bool Match(const char *idxName) const; + const vespalib::string& get_prefix() const noexcept { return _prefix; } }; private: typedef vespalib::hash_set<vespalib::string> Set; IDocsumEnvironment *_env; - IndexPrefix *_legalPrefixes; + std::vector<IndexPrefix> _legalPrefixes; Set _legalIndexes; bool IsLegalIndexPrefix(const char *idxName) const { - for (const IndexPrefix *pt = _legalPrefixes; - pt != nullptr; - pt = pt->_next) - { - if (pt->Match(idxName)) + for (auto& prefix : _legalPrefixes ) { + if (prefix.Match(idxName)) { return true; + } } return false; } @@ -63,8 +57,7 @@ public: **/ void AddLegalIndexPrefix(const char *prefix) { - //Self destructing construction - new IndexPrefix(prefix, &_legalPrefixes); + _legalPrefixes.emplace_back(prefix); } diff --git a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp index c107071d619..0dd15ad888e 100644 --- a/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp +++ b/searchsummary/src/vespa/searchsummary/docsummary/summaryfieldconverter.cpp @@ -243,7 +243,7 @@ class SummaryFieldValueConverter : protected ConstFieldValueVisitor void visit(const BoolFieldValue &value) override { visitPrimitive(value); } void visit(const ByteFieldValue &value) override { int8_t signedValue = value.getAsByte(); - _field_value.reset(new ShortFieldValue(signedValue)); + _field_value = std::make_unique<ShortFieldValue>(signedValue); } void visit(const DoubleFieldValue &value) override { visitPrimitive(value); } void visit(const FloatFieldValue &value) override { visitPrimitive(value); } |