summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-04-08 12:39:13 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-04-08 12:39:13 +0000
commitd2256956ffc3b4253706b443731be93e3c77d594 (patch)
tree89aeb3276d3bf6118e6798d5f292d9721da3a28f /document
parent43de4cdb878ec77d95a47bb8d8c46bc26b0e8f7e (diff)
Avoid CloneablePtr
Diffstat (limited to 'document')
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.h2
-rw-r--r--document/src/vespa/document/fieldvalue/variablemap.cpp14
-rw-r--r--document/src/vespa/document/fieldvalue/variablemap.h8
-rw-r--r--document/src/vespa/document/select/resultlist.cpp38
-rw-r--r--document/src/vespa/document/select/resultlist.h2
-rw-r--r--document/src/vespa/document/select/value.cpp6
6 files changed, 35 insertions, 35 deletions
diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h
index a45e42539ee..c2c91e81a90 100644
--- a/document/src/vespa/document/fieldvalue/fieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/fieldvalue.h
@@ -37,8 +37,6 @@ public:
};
using PathRange = FieldPath::Range<FieldPath::const_iterator>;
using UP = std::unique_ptr<FieldValue>;
- using SP = std::shared_ptr<FieldValue>;
- using CP = vespalib::CloneablePtr<FieldValue>;
using XmlOutputStream = vespalib::xml::XmlOutputStream;
virtual ~FieldValue() = default;
diff --git a/document/src/vespa/document/fieldvalue/variablemap.cpp b/document/src/vespa/document/fieldvalue/variablemap.cpp
index 1ad4e1b716b..be973782eb3 100644
--- a/document/src/vespa/document/fieldvalue/variablemap.cpp
+++ b/document/src/vespa/document/fieldvalue/variablemap.cpp
@@ -28,8 +28,16 @@ IndexValue::IndexValue(const FieldValue& key_)
IndexValue::IndexValue(IndexValue && rhs) noexcept = default;
IndexValue & IndexValue::operator = (IndexValue && rhs) noexcept = default;
-IndexValue::IndexValue(const IndexValue & rhs) = default;
-IndexValue & IndexValue::operator = (const IndexValue & rhs) = default;
+IndexValue::IndexValue(const IndexValue & rhs) :
+ index(rhs.index),
+ key(rhs.key ? rhs.key->clone() : nullptr)
+{}
+IndexValue & IndexValue::operator = (const IndexValue & rhs) {
+ IndexValue tmp(rhs);
+ std::swap(index, tmp.index);
+ std::swap(key, tmp.key);
+ return *this;
+}
IndexValue::~IndexValue() = default;
@@ -44,8 +52,6 @@ IndexValue::toString() const {
VariableMap::VariableMap(VariableMap && rhs) noexcept = default;
VariableMap & VariableMap::operator = (VariableMap && rhs) noexcept = default;
-VariableMap::VariableMap(const VariableMap & rhs) = default;
-VariableMap & VariableMap::operator = (const VariableMap & rhs) = default;
VariableMap::VariableMap() = default;
VariableMap::~VariableMap() = default;
diff --git a/document/src/vespa/document/fieldvalue/variablemap.h b/document/src/vespa/document/fieldvalue/variablemap.h
index 68b8bcf09e8..70f347133c4 100644
--- a/document/src/vespa/document/fieldvalue/variablemap.h
+++ b/document/src/vespa/document/fieldvalue/variablemap.h
@@ -2,9 +2,9 @@
#pragma once
-#include <vespa/vespalib/util/memory.h>
#include <vespa/vespalib/stllike/string.h>
#include <map>
+#include <memory>
namespace document {
class FieldValue;
@@ -28,7 +28,7 @@ public:
bool operator==(const IndexValue& other) const;
int index; // For array
- vespalib::CloneablePtr<FieldValue> key; // For map/wset
+ std::unique_ptr<FieldValue> key; // For map/wset
};
using VariableMapT = std::map<vespalib::string, IndexValue>;
@@ -38,8 +38,8 @@ public:
VariableMap();
VariableMap(VariableMap && rhs) noexcept;
VariableMap & operator = (VariableMap && rhs) noexcept;
- VariableMap(const VariableMap & rhs);
- VariableMap & operator = (const VariableMap & rhs);
+ VariableMap(const VariableMap & rhs) = delete;
+ VariableMap & operator = (const VariableMap & rhs) = delete;
~VariableMap();
vespalib::string toString() const;
};
diff --git a/document/src/vespa/document/select/resultlist.cpp b/document/src/vespa/document/select/resultlist.cpp
index e6ce79fe117..c690a15e517 100644
--- a/document/src/vespa/document/select/resultlist.cpp
+++ b/document/src/vespa/document/select/resultlist.cpp
@@ -16,7 +16,7 @@ ResultList::ResultList(const Result& result) {
}
void
-ResultList::add(fieldvalue::VariableMap variables, const Result& result)
+ResultList::add(VariableMap variables, const Result& result)
{
_results.emplace_back(std::move(variables), &result);
}
@@ -64,32 +64,33 @@ ResultList::combineResults() const {
}
bool
-ResultList::combineVariables(
- fieldvalue::VariableMap& output,
- const fieldvalue::VariableMap& input) const
+ResultList::combineVariables(VariableMap& combination, const VariableMap& a, const VariableMap& b) const
{
// First, verify that all variables are overlapping
- for (const auto & ovar : output) {
- auto found(input.find(ovar.first));
+ for (const auto & ovar : a) {
+ auto found(b.find(ovar.first));
- if (found != input.end()) {
+ if (found != b.end()) {
if (!(found->second == ovar.second)) {
return false;
}
}
}
- for (const auto & ivar : input) {
- auto found(output.find(ivar.first));
- if (found != output.end()) {
+ for (const auto & ivar : b) {
+ auto found(a.find(ivar.first));
+ if (found != a.end()) {
if (!(found->second == ivar.second)) {
return false;
}
}
}
// Ok, variables are overlapping. Add all variables from input to output.
- for (const auto & ivar : input) {
- output[ivar.first] = ivar.second;
+ for (const auto & var : a) {
+ combination[var.first] = var.second;
+ }
+ for (const auto & var : b) {
+ combination[var.first] = var.second;
}
return true;
@@ -103,9 +104,8 @@ ResultList::operator&&(const ResultList& other) const
std::bitset<3> resultForNoVariables;
for (const auto & it : _results) {
for (const auto & it2 : other._results) {
- fieldvalue::VariableMap vars = it.first;
-
- if (combineVariables(vars, it2.first)) {
+ VariableMap vars;
+ if ( combineVariables(vars, it.first, it2.first) ) {
const Result & result = *it.second && *it2.second;
if (vars.empty()) {
resultForNoVariables.set(result.toEnum());
@@ -117,7 +117,7 @@ ResultList::operator&&(const ResultList& other) const
}
for (uint32_t i(0); i < resultForNoVariables.size(); i++) {
if (resultForNoVariables[i]) {
- results.add(fieldvalue::VariableMap(), Result::fromEnum(i));
+ results.add(VariableMap(), Result::fromEnum(i));
}
}
@@ -132,8 +132,8 @@ ResultList::operator||(const ResultList& other) const
std::bitset<3> resultForNoVariables;
for (const auto & it : _results) {
for (const auto & it2 : other._results) {
- fieldvalue::VariableMap vars = it.first;
- if (combineVariables(vars, it2.first)) {
+ VariableMap vars;
+ if (combineVariables(vars, it.first, it2.first)) {
const Result & result = *it.second || *it2.second;
if (vars.empty()) {
resultForNoVariables.set(result.toEnum());
@@ -145,7 +145,7 @@ ResultList::operator||(const ResultList& other) const
}
for (uint32_t i(0); i < resultForNoVariables.size(); i++) {
if (resultForNoVariables[i]) {
- results.add(fieldvalue::VariableMap(), Result::fromEnum(i));
+ results.add(VariableMap(), Result::fromEnum(i));
}
}
diff --git a/document/src/vespa/document/select/resultlist.h b/document/src/vespa/document/select/resultlist.h
index 4099c1e39ba..b7893471374 100644
--- a/document/src/vespa/document/select/resultlist.h
+++ b/document/src/vespa/document/select/resultlist.h
@@ -50,7 +50,7 @@ public:
private:
Results _results;
- bool combineVariables(VariableMap& output, const VariableMap& input) const;
+ bool combineVariables(VariableMap & combination, const VariableMap& output, const VariableMap& input) const;
};
inline bool operator==(const ResultList& list, const Result& other) {
diff --git a/document/src/vespa/document/select/value.cpp b/document/src/vespa/document/select/value.cpp
index a36a25103da..4f46cb1c30f 100644
--- a/document/src/vespa/document/select/value.cpp
+++ b/document/src/vespa/document/select/value.cpp
@@ -392,11 +392,7 @@ fieldvalue::VariableMap
cloneMap(const fieldvalue::VariableMap &map) {
fieldvalue::VariableMap m;
for (const auto & item : map) {
- if (item.second.key) {
- m.emplace(item.first, fieldvalue::IndexValue(*item.second.key));
- } else {
- m.emplace(item.first, fieldvalue::IndexValue(item.second.index));
- }
+ m.emplace(item.first, item.second);
}
return m;
}