diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-08-07 16:19:34 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-08-07 16:19:34 +0000 |
commit | b5a9416c8546f0bf8c5e59d64ea1e4102f5eec84 (patch) | |
tree | ff7e489203bf248fcb45a388aa42dd322085b5c4 /document | |
parent | dc10b82a2e54294752f85c4949229424a07cbe94 (diff) |
Do not compute the hash on temporary sets. Wait till done.
Diffstat (limited to 'document')
-rw-r--r-- | document/src/tests/fieldsettest.cpp | 14 | ||||
-rw-r--r-- | document/src/vespa/document/fieldset/fieldsetrepo.cpp | 6 | ||||
-rw-r--r-- | document/src/vespa/document/fieldset/fieldsets.cpp | 11 | ||||
-rw-r--r-- | document/src/vespa/document/fieldset/fieldsets.h | 8 |
4 files changed, 26 insertions, 13 deletions
diff --git a/document/src/tests/fieldsettest.cpp b/document/src/tests/fieldsettest.cpp index 2642bbe23ce..472ede57b6d 100644 --- a/document/src/tests/fieldsettest.cpp +++ b/document/src/tests/fieldsettest.cpp @@ -291,20 +291,22 @@ TEST(FieldCollectionTest, testHash ) { const DocumentType & type = *repo.getDocumentType("testdoctype1"); FieldCollection fc(type); EXPECT_EQ(0ul, fc.hash()); - fc.insert(type.getField("headerval")); + fc.insertField(type.getField("headerval")); + EXPECT_EQ(0ul, fc.hash()); + fc.complete(); EXPECT_EQ(0x548599858c77ef83ul, fc.hash()); - fc.insert(type.getField("hstringval")); + fc.insertField(type.getField("hstringval")).complete(); EXPECT_EQ(0x4a7ff2406d36a9b0ul, fc.hash()); - fc.insert(type.getField("headerval")); + fc.insertField(type.getField("headerval")).complete(); EXPECT_EQ(0x4a7ff2406d36a9b0ul, fc.hash()); FieldCollection fc2(type); EXPECT_EQ(0ul, fc2.hash()); - fc2.insert(type.getField("hstringval")); + fc2.insertField(type.getField("hstringval")).complete(); EXPECT_EQ(0x1e0918531b19734ul, fc2.hash()); - fc2.insert(type.getField("headerval")); + fc2.insertField(type.getField("headerval")).complete(); EXPECT_EQ(fc.hash(), fc2.hash()); - fc2.insert(type.getField("headerval")); + fc2.insertField(type.getField("headerval")).complete(); EXPECT_EQ(fc.hash(), fc2.hash()); } diff --git a/document/src/vespa/document/fieldset/fieldsetrepo.cpp b/document/src/vespa/document/fieldset/fieldsetrepo.cpp index 614a8740f90..e202a370559 100644 --- a/document/src/vespa/document/fieldset/fieldsetrepo.cpp +++ b/document/src/vespa/document/fieldset/fieldsetrepo.cpp @@ -50,13 +50,13 @@ parseFieldCollection(const DocumentTypeRepo& repo, const DocumentType::FieldSet * fs = type.getFieldSet(token); if (fs) { for (const auto & fieldName : fs->getFields()) { - collection->insert(type.getField(fieldName)); + collection->insertField(type.getField(fieldName)); } } else { - collection->insert(type.getField(token)); + collection->insertField(type.getField(token)); } } - + collection->complete(); return collection; } diff --git a/document/src/vespa/document/fieldset/fieldsets.cpp b/document/src/vespa/document/fieldset/fieldsets.cpp index d878d38be14..ae0703ed66b 100644 --- a/document/src/vespa/document/fieldset/fieldsets.cpp +++ b/document/src/vespa/document/fieldset/fieldsets.cpp @@ -28,6 +28,8 @@ FieldCollection::FieldCollection(const DocumentType& type) { } +FieldCollection::FieldCollection(const FieldCollection&) = default; + FieldCollection::~FieldCollection() = default; bool @@ -65,10 +67,13 @@ FieldCollection::contains(const FieldSet& fields) const return false; } -void -FieldCollection::insert(const Field& f) -{ +FieldCollection & +FieldCollection::insertField(const Field& f) { _set.insert(&f); + return *this; +} +void +FieldCollection::complete() { _hash = computeHash(_set); } diff --git a/document/src/vespa/document/fieldset/fieldsets.h b/document/src/vespa/document/fieldset/fieldsets.h index eac35244012..44b6b8a6405 100644 --- a/document/src/vespa/document/fieldset/fieldsets.h +++ b/document/src/vespa/document/fieldset/fieldsets.h @@ -42,6 +42,8 @@ public: typedef std::unique_ptr<FieldCollection> UP; FieldCollection(const DocumentType& docType); + FieldCollection(const FieldCollection &); + FieldCollection(FieldCollection&&) = default; ~FieldCollection() override; bool contains(const FieldSet& fields) const override; @@ -57,7 +59,11 @@ public: /** * Inserts the given field into the collection. */ - void insert(const Field& f); + FieldCollection & insertField(const Field& f); + /** + * Must be called after all fields are inserted + */ + void complete(); /** * Returns all the fields contained in this collection. |