aboutsummaryrefslogtreecommitdiffstats
path: root/document/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-07 09:39:18 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-07 09:39:18 +0000
commita4cd8a591a4050b7bb5907919b597f3ea999d883 (patch)
treeb74fae5254ad3d6f8317f0ec2f510061ed3c531b /document/src
parentfc55e27fb014beb2eba8367131805bf57c35b23a (diff)
No reuse, so just use return value optimisation.
Diffstat (limited to 'document/src')
-rw-r--r--document/src/vespa/document/fieldvalue/structfieldvalue.cpp19
-rw-r--r--document/src/vespa/document/fieldvalue/structfieldvalue.h2
2 files changed, 9 insertions, 12 deletions
diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
index 555964d8b34..fbe6dadb320 100644
--- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp
@@ -79,14 +79,16 @@ bool StructFieldValue::serializeField(int field_id, uint16_t version, FieldValue
}
}
-void StructFieldValue::getRawFieldIds(vector<int> &raw_ids) const {
- raw_ids.clear();
+vector<int>
+StructFieldValue::getRawFieldIds() const {
+ vector<int> raw_ids;
raw_ids.reserve(_fields.getEntries().size());
for (const SerializableArray::Entry & entry : _fields.getEntries()) {
raw_ids.emplace_back(entry.id());
}
sort(raw_ids.begin(), raw_ids.end());
raw_ids.erase(unique(raw_ids.begin(), raw_ids.end()), raw_ids.end());
+ return raw_ids;
}
void
@@ -242,10 +244,8 @@ StructFieldValue::compare(const FieldValue& otherOrg) const
}
const auto & other = static_cast<const StructFieldValue&>(otherOrg);
- std::vector<int> a;
- getRawFieldIds(a);
- std::vector<int> b;
- other.getRawFieldIds(b);
+ std::vector<int> a = getRawFieldIds();
+ std::vector<int> b = other.getRawFieldIds();
for (size_t i(0); i < std::min(a.size(), b.size()); i++) {
if (a[i] != b[i]) {
@@ -337,12 +337,9 @@ struct StructFieldValue::FieldIterator : public StructuredIterator {
explicit FieldIterator(const StructFieldValue& s)
: _struct(s),
- _ids(),
+ _ids(s.getRawFieldIds()),
_cur(_ids.begin())
- {
- s.getRawFieldIds(_ids);
- _cur = _ids.begin();
- }
+ { }
void skipTo(int fieldId) {
while (_cur != _ids.end() && fieldId != *_cur) {
diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h
index cbf62ce54fa..24e143ddc27 100644
--- a/document/src/vespa/document/fieldvalue/structfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h
@@ -54,7 +54,7 @@ public:
uint16_t getVersion() const { return _version; }
// raw_ids may contain ids for elements not in the struct's datatype.
- void getRawFieldIds(std::vector<int> &raw_ids) const;
+ std::vector<int> getRawFieldIds() const;
void getRawFieldIds(std::vector<int> &raw_ids, const FieldSet& fieldSet) const;
void accept(FieldValueVisitor &visitor) override { visitor.visit(*this); }