diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-17 09:25:04 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-17 09:25:04 +0000 |
commit | d092c8e45fe74f0fe7808a6d4fa363fb0a009181 (patch) | |
tree | 153d0b894a87fc4b6044893dc3f03bd744d619c3 /document | |
parent | b1bc742e8ac18dd41ea8f19919005257fbfa277b (diff) |
GC unused code and simplify StructFieldValue.
Diffstat (limited to 'document')
5 files changed, 19 insertions, 42 deletions
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 93bcd61ddb0..9a3d9c94a91 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/document/base/testdocman.h> -#include <vespa/vespalib/io/fileutil.h> #include <vespa/document/datatype/annotationreferencedatatype.h> #include <vespa/document/fieldvalue/iteratorhandler.h> #include <vespa/document/repo/configbuilder.h> @@ -9,6 +8,9 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/document/serialization/vespadocumentserializer.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/vespalib/io/fileutil.h> +#include <vespa/vespalib/util/growablebytebuffer.h> + #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/util/bytebuffer.h> @@ -28,10 +30,15 @@ using namespace fieldvalue; TEST(DocumentTest, testSizeOf) { + EXPECT_EQ(24u, sizeof(std::vector<char>)); + EXPECT_EQ(24u, sizeof(vespalib::alloc::Alloc)); + EXPECT_EQ(56u, sizeof(ByteBuffer)); + EXPECT_EQ(32u, sizeof(vespalib::GrowableByteBuffer)); + EXPECT_EQ(56u, sizeof(ByteBuffer)); EXPECT_EQ(88ul, sizeof(IdString)); EXPECT_EQ(104ul, sizeof(DocumentId)); - EXPECT_EQ(208ul, sizeof(Document)); - EXPECT_EQ(72ul, sizeof(StructFieldValue)); + EXPECT_EQ(200ul, sizeof(Document)); + EXPECT_EQ(64ul, sizeof(StructFieldValue)); EXPECT_EQ(24ul, sizeof(StructuredFieldValue)); EXPECT_EQ(64ul, sizeof(SerializableArray)); } @@ -63,7 +70,7 @@ TEST(DocumentTest, testFieldPath) class Handler : public fieldvalue::IteratorHandler { public: Handler(); - ~Handler(); + ~Handler() override; const std::string & getResult() const { return _result; } private: void onPrimitive(uint32_t, const Content&) override { diff --git a/document/src/vespa/document/fieldvalue/serializablearray.cpp b/document/src/vespa/document/fieldvalue/serializablearray.cpp index ff0fe3dbdf0..89b54b3e51a 100644 --- a/document/src/vespa/document/fieldvalue/serializablearray.cpp +++ b/document/src/vespa/document/fieldvalue/serializablearray.cpp @@ -26,7 +26,6 @@ public: } -SerializableArray::Statistics SerializableArray::_stats; SerializableArray::SerializableArray() : _serializedCompression(CompressionConfig::NONE), diff --git a/document/src/vespa/document/fieldvalue/serializablearray.h b/document/src/vespa/document/fieldvalue/serializablearray.h index 7ee09f592b2..102b4519c79 100644 --- a/document/src/vespa/document/fieldvalue/serializablearray.h +++ b/document/src/vespa/document/fieldvalue/serializablearray.h @@ -35,25 +35,6 @@ namespace serializablearray { class SerializableArray : public vespalib::Cloneable { public: - // Counts set during serialization, in order to provide metrics for how - // often we use cached version, and how often we compress. - struct Statistics { - uint64_t _usedCachedSerializationCount; - uint64_t _compressedDocumentCount; - uint64_t _compressionDidntHelpCount; - uint64_t _uncompressableCount; - uint64_t _serializedUncompressed; - uint64_t _inputWronglySerialized; - - Statistics() - : _usedCachedSerializationCount(0), - _compressedDocumentCount(0), - _compressionDidntHelpCount(0), - _uncompressableCount(0), - _serializedUncompressed(0), - _inputWronglySerialized(0) {} - }; - /** * Contains the id of a field, the size and a buffer reference that is either * a relative offset to a common buffer, or the buffer itself it it is not. @@ -97,12 +78,6 @@ public: static const uint32_t ReservedId = 100; static const uint32_t ReservedIdUpper = 128; - -private: - static Statistics _stats; - -public: - static Statistics& getStatistics() { return _stats; } using CP = vespalib::CloneablePtr<SerializableArray>; using UP = std::unique_ptr<SerializableArray>; using ByteBufferUP = std::unique_ptr<ByteBuffer>; diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp index 1d74e99208a..fbdc08bee0e 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp @@ -48,15 +48,14 @@ StructFieldValue::Chunks::~Chunks() = default; void StructFieldValue::Chunks::push_back(SerializableArray::UP item) { - assert(_sz < 2); - _chunks[_sz++].reset(item.release()); + assert(size() < 2); + _chunks[size()] = std::move(item); } void StructFieldValue::Chunks::clear() { _chunks[0].reset(); _chunks[1].reset(); - _sz = 0; } const StructDataType & @@ -182,8 +181,8 @@ StructFieldValue::getFieldValue(const Field& field) const nbostream stream(buf.c_str(), buf.size()); FieldValue::UP value(field.getDataType().createFieldValue()); if ((_repo == nullptr) && (_doc_type != nullptr)) { - std::unique_ptr<const DocumentTypeRepo> tmpRepo(new DocumentTypeRepo(*_doc_type)); - createFV(*value, *tmpRepo, stream, *_doc_type, _version); + DocumentTypeRepo tmpRepo(*_doc_type); + createFV(*value, tmpRepo, stream, *_doc_type, _version); } else { createFV(*value, *_repo, stream, *_doc_type, _version); } @@ -262,7 +261,7 @@ StructFieldValue::setFieldValue(const Field& field, FieldValue::UP value) _chunks.push_back(std::make_unique<SerializableArray>()); } - _chunks.back().set(fieldId, std::move(serialized)); + _chunks[0].set(fieldId, std::move(serialized)); _hasChanged = true; } diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index b5b15e9dfce..30500229813 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -27,19 +27,16 @@ class StructFieldValue : public StructuredFieldValue public: class Chunks { public: - Chunks() : _sz(0) { } + Chunks() { } ~Chunks(); SerializableArray & operator [] (size_t i) { return *_chunks[i]; } const SerializableArray & operator [] (size_t i) const { return *_chunks[i]; } VESPA_DLL_LOCAL void push_back(SerializableArray::UP item); - SerializableArray & back() { return *_chunks[_sz-1]; } - const SerializableArray & back() const { return *_chunks[_sz-1]; } - size_t size() const { return _sz; } - bool empty() const { return _sz == 0; } + size_t size() const { return _chunks[1] ? 2 : _chunks[0] ? 1 : 0; } + bool empty() const { return !_chunks[0]; } VESPA_DLL_LOCAL void clear(); private: SerializableArray::CP _chunks[2]; - size_t _sz; }; private: Chunks _chunks; |