diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-04-06 10:25:02 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-04-06 10:25:02 +0000 |
commit | e1696ca01338d1df06fa12452544c3e62ac3267c (patch) | |
tree | e8eac1330843d33ebd58bebe2ba84db5695c0871 /vsm | |
parent | 3c4cddd0b08666e497996e7f5b499e5a86fc68eb (diff) |
Reduce use of CloneablePtr
Diffstat (limited to 'vsm')
-rw-r--r-- | vsm/src/tests/docsum/docsum.cpp | 8 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/common/documenttypemapping.cpp | 6 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/common/storagedocument.h | 4 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/vsm/docsumfieldspec.cpp | 5 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/vsm/docsumfieldspec.h | 7 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/vsm/docsumfilter.cpp | 34 |
6 files changed, 33 insertions, 31 deletions
diff --git a/vsm/src/tests/docsum/docsum.cpp b/vsm/src/tests/docsum/docsum.cpp index 35553c6f98c..475489d2f5a 100644 --- a/vsm/src/tests/docsum/docsum.cpp +++ b/vsm/src/tests/docsum/docsum.cpp @@ -204,12 +204,12 @@ DocsumTest::testSlimeFieldWriter() { FieldPath path; type.buildFieldPath(path, "a"); - fields.push_back(DocsumFieldSpec::FieldIdentifier(0, path)); + fields.push_back(DocsumFieldSpec::FieldIdentifier(0, std::move(path))); } { FieldPath path; type.buildFieldPath(path, "c.e"); - fields.push_back(DocsumFieldSpec::FieldIdentifier(0, path)); + fields.push_back(DocsumFieldSpec::FieldIdentifier(0, std::move(path))); } sfw.setInputFields(fields); TEST_DO(assertSlimeFieldWriter(sfw, value, "{\"a\":\"foo\",\"c\":{\"e\":\"qux\"}}")); @@ -257,14 +257,14 @@ DocsumTest::requireThatSlimeFieldWriterHandlesMap() { FieldPath path; mapType.buildFieldPath(path, "value.b"); - fields.push_back(DocsumFieldSpec::FieldIdentifier(0, path)); + fields.push_back(DocsumFieldSpec::FieldIdentifier(0, std::move(path))); } sfw.setInputFields(fields); TEST_DO(assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"b\":\"bar\"}}]")); { FieldPath path; mapType.buildFieldPath(path, "{k1}.a"); - fields[0] = DocsumFieldSpec::FieldIdentifier(0, path); + fields[0] = DocsumFieldSpec::FieldIdentifier(0, std::move(path)); } sfw.clear(); sfw.setInputFields(fields); diff --git a/vsm/src/vespa/vsm/common/documenttypemapping.cpp b/vsm/src/vespa/vsm/common/documenttypemapping.cpp index 2379103653e..7886c44b2e0 100644 --- a/vsm/src/vespa/vsm/common/documenttypemapping.cpp +++ b/vsm/src/vespa/vsm/common/documenttypemapping.cpp @@ -45,13 +45,13 @@ bool DocumentTypeMapping::prepareBaseDoc(SharedFieldPathMap & map) const { FieldPathMapMapT::const_iterator found = _fieldMap.find(_defaultDocumentTypeName); if (found != _fieldMap.end()) { - map.reset(new FieldPathMapT(found->second)); + map = std::make_shared<FieldPathMapT>(found->second); LOG(debug, "Found FieldPathMap for default document type '%s' with %zd elements", _defaultDocumentTypeName.c_str(), map->size()); } else { LOG(warning, "No FieldPathMap found for default document type '%s'. Using empty one", _defaultDocumentTypeName.c_str()); - map.reset(new FieldPathMapT()); + map = std::make_shared<FieldPathMapT>(); } return true; } @@ -70,7 +70,7 @@ void DocumentTypeMapping::buildFieldMap( highestFNo++; FieldPathMapT & fieldMap = _fieldMap[typeId]; - fieldMap.assign(highestFNo, FieldPath()); + fieldMap.resize(highestFNo); size_t validCount(0); for (StringFieldIdTMapT::const_iterator it = fieldList.begin(), mt = fieldList.end(); it != mt; it++) { diff --git a/vsm/src/vespa/vsm/common/storagedocument.h b/vsm/src/vespa/vsm/common/storagedocument.h index 46a3e2f3251..a7f21cb052f 100644 --- a/vsm/src/vespa/vsm/common/storagedocument.h +++ b/vsm/src/vespa/vsm/common/storagedocument.h @@ -17,7 +17,7 @@ public: class SubDocument { public: - SubDocument() : _fieldValue(NULL) {} + SubDocument() : _fieldValue(nullptr) {} SubDocument(document::FieldValue *fv, document::FieldValue::PathRange nested) : _fieldValue(fv), _range(nested) @@ -43,7 +43,7 @@ public: ~StorageDocument(); const document::Document &docDoc() const { return *_doc; } - bool valid() const { return _doc.get() != NULL; } + bool valid() const { return _doc.get() != nullptr; } const SubDocument &getComplexField(FieldIdT fId) const; const document::FieldValue *getField(FieldIdT fId) const override; bool setField(FieldIdT fId, document::FieldValue::UP fv) override ; diff --git a/vsm/src/vespa/vsm/vsm/docsumfieldspec.cpp b/vsm/src/vespa/vsm/vsm/docsumfieldspec.cpp index ba8310a9879..936aaaa2091 100644 --- a/vsm/src/vespa/vsm/vsm/docsumfieldspec.cpp +++ b/vsm/src/vespa/vsm/vsm/docsumfieldspec.cpp @@ -10,9 +10,12 @@ DocsumFieldSpec::FieldIdentifier::FieldIdentifier() : DocsumFieldSpec::FieldIdentifier::FieldIdentifier(FieldIdT id, FieldPath path) : _id(id), - _path(path) + _path(std::move(path)) { } +DocsumFieldSpec::FieldIdentifier::FieldIdentifier(FieldIdentifier &&) noexcept = default; +DocsumFieldSpec::FieldIdentifier & DocsumFieldSpec::FieldIdentifier::operator=(FieldIdentifier &&) noexcept = default; +DocsumFieldSpec::FieldIdentifier::~FieldIdentifier() = default; DocsumFieldSpec::DocsumFieldSpec() : _resultType(search::docsummary::RES_INT), diff --git a/vsm/src/vespa/vsm/vsm/docsumfieldspec.h b/vsm/src/vespa/vsm/vsm/docsumfieldspec.h index 5acef140468..db6ee9fa223 100644 --- a/vsm/src/vespa/vsm/vsm/docsumfieldspec.h +++ b/vsm/src/vespa/vsm/vsm/docsumfieldspec.h @@ -24,6 +24,11 @@ public: public: FieldIdentifier(); FieldIdentifier(FieldIdT id, FieldPath path); + FieldIdentifier(FieldIdentifier &&) noexcept; + FieldIdentifier & operator=(FieldIdentifier &&) noexcept; + FieldIdentifier(const FieldIdentifier &) = delete; + FieldIdentifier & operator=(const FieldIdentifier &) = delete; + ~FieldIdentifier(); FieldIdT getId() const { return _id; } const FieldPath & getPath() const { return _path; } }; @@ -58,7 +63,7 @@ public: } const FieldIdentifier & getOutputField() const { return _outputField; } - void setOutputField(const FieldIdentifier & outputField) { _outputField = outputField; } + void setOutputField(FieldIdentifier outputField) { _outputField = std::move(outputField); } const FieldIdentifierVector & getInputFields() const { return _inputFields; } FieldIdentifierVector & getInputFields() { return _inputFields; } }; diff --git a/vsm/src/vespa/vsm/vsm/docsumfilter.cpp b/vsm/src/vespa/vsm/vsm/docsumfilter.cpp index bd16c687fc7..42ab32afbf7 100644 --- a/vsm/src/vespa/vsm/vsm/docsumfilter.cpp +++ b/vsm/src/vespa/vsm/vsm/docsumfilter.cpp @@ -118,6 +118,18 @@ public: namespace vsm { +FieldPath +copyPathButFirst(const FieldPath & rhs) { + // skip the element that correspond to the start field value + FieldPath path; + if ( ! rhs.empty()) { + for (auto it = rhs.begin() + 1; it != rhs.end(); it++) { + path.push_back(std::make_unique<document::FieldPathEntry>(**it)); + } + } + return path; +} + void DocsumFilter::prepareFieldSpec(DocsumFieldSpec & spec, const DocsumTools::FieldSpec & toolsSpec, const FieldMap & fieldMap, const FieldPathMapT & fieldPathMap) @@ -128,14 +140,7 @@ DocsumFilter::prepareFieldSpec(DocsumFieldSpec & spec, const DocsumTools::FieldS FieldIdT field = fieldMap.fieldNo(name); if (field != FieldMap::npos) { if (field < fieldPathMap.size()) { - if (!fieldPathMap[field].empty()) { - // skip the element that correspond to the start field value - spec.setOutputField(DocsumFieldSpec::FieldIdentifier - (field, FieldPath(fieldPathMap[field].begin() + 1, - fieldPathMap[field].end()))); - } else { - spec.setOutputField(DocsumFieldSpec::FieldIdentifier(field, FieldPath())); - } + spec.setOutputField(DocsumFieldSpec::FieldIdentifier(field, copyPathButFirst(fieldPathMap[field]))); } else { LOG(warning, "Could not find a field path for field '%s' with id '%d'", name.c_str(), field); spec.setOutputField(DocsumFieldSpec::FieldIdentifier(field, FieldPath())); @@ -152,18 +157,7 @@ DocsumFilter::prepareFieldSpec(DocsumFieldSpec & spec, const DocsumTools::FieldS if (field != FieldMap::npos) { if (field < fieldPathMap.size()) { LOG(debug, "field %u < map size %zu", field, fieldPathMap.size()); - if (!fieldPathMap[field].empty()) { - FieldPath relPath(fieldPathMap[field].begin() + 1, - fieldPathMap[field].end()); - LOG(debug, "map[%u] -> %zu elements", field, fieldPathMap[field].end() - fieldPathMap[field].begin()); - // skip the element that correspond to the start field value - spec.getInputFields().push_back(DocsumFieldSpec::FieldIdentifier - (field, FieldPath(fieldPathMap[field].begin() + 1, - fieldPathMap[field].end()))); - } else { - LOG(debug, "map[%u] empty", field); - spec.getInputFields().push_back(DocsumFieldSpec::FieldIdentifier(field, FieldPath())); - } + spec.getInputFields().push_back(DocsumFieldSpec::FieldIdentifier(field, copyPathButFirst(fieldPathMap[field]))); } else { LOG(warning, "Could not find a field path for field '%s' with id '%d'", name.c_str(), field); spec.getInputFields().push_back(DocsumFieldSpec::FieldIdentifier(field, FieldPath())); |