diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-23 16:18:43 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-23 16:18:43 +0000 |
commit | 19c8f9406297f359c0e04e7bda9f12ef625f1df6 (patch) | |
tree | fd476b24670fd2a03211a0536d918d8de6fff37b /document | |
parent | 7a97a9c569be961b79bea5990296f414d7f3f935 (diff) |
Add an extra indirection to the rarely used owned buffers, in order to keep the frequently accesed members in StructFieldValue close
Diffstat (limited to 'document')
-rw-r--r-- | document/src/tests/documenttestcase.cpp | 8 | ||||
-rw-r--r-- | document/src/vespa/document/util/bytebuffer.cpp | 24 | ||||
-rw-r--r-- | document/src/vespa/document/util/bytebuffer.h | 3 |
3 files changed, 22 insertions, 13 deletions
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index 956f2d07e85..6993596392c 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -32,14 +32,14 @@ TEST(DocumentTest, testSizeOf) { EXPECT_EQ(24u, sizeof(std::vector<char>)); EXPECT_EQ(24u, sizeof(vespalib::alloc::Alloc)); - EXPECT_EQ(40u, sizeof(ByteBuffer)); + EXPECT_EQ(24u, sizeof(ByteBuffer)); EXPECT_EQ(32u, sizeof(vespalib::GrowableByteBuffer)); EXPECT_EQ(88ul, sizeof(IdString)); EXPECT_EQ(104ul, sizeof(DocumentId)); - EXPECT_EQ(248ul, sizeof(Document)); - EXPECT_EQ(112ul, sizeof(StructFieldValue)); + EXPECT_EQ(232ul, sizeof(Document)); + EXPECT_EQ(96ul, sizeof(StructFieldValue)); EXPECT_EQ(16ul, sizeof(StructuredFieldValue)); - EXPECT_EQ(72ul, sizeof(SerializableArray)); + EXPECT_EQ(56ul, sizeof(SerializableArray)); } TEST(DocumentTest, testFieldPath) diff --git a/document/src/vespa/document/util/bytebuffer.cpp b/document/src/vespa/document/util/bytebuffer.cpp index e1999c34288..bc7e726cb06 100644 --- a/document/src/vespa/document/util/bytebuffer.cpp +++ b/document/src/vespa/document/util/bytebuffer.cpp @@ -69,25 +69,33 @@ ByteBuffer::ByteBuffer(const char* buffer, uint32_t len) : { } -ByteBuffer::ByteBuffer(Alloc buffer, uint32_t len) : - _buffer(static_cast<char *>(buffer.get())), +ByteBuffer::ByteBuffer(Alloc buffer, uint32_t len) + : _buffer(static_cast<const char *>(buffer.get())), + _len(len), + _pos(0), + _ownedBuffer(std::make_unique<Alloc>(std::move(buffer))) +{ +} + +ByteBuffer::ByteBuffer(std::unique_ptr<Alloc> buffer, uint32_t len) + : _buffer(static_cast<const char *>(buffer->get())), _len(len), _pos(0), _ownedBuffer(std::move(buffer)) { } -ByteBuffer::ByteBuffer(const ByteBuffer& rhs) : - _buffer(nullptr), +ByteBuffer::ByteBuffer(const ByteBuffer& rhs) + : _buffer(nullptr), _len(rhs._len), _pos(rhs._pos), _ownedBuffer() { if (rhs._len > 0 && rhs._buffer) { - Alloc buf = Alloc::alloc(rhs._len); + auto buf = Alloc::alloc(rhs._len); memcpy(buf.get(), rhs._buffer, rhs._len); - _ownedBuffer = std::move(buf); - _buffer = static_cast<const char *>(_ownedBuffer.get()); + _buffer = static_cast<const char *>(buf.get()); + _ownedBuffer = std::make_unique<Alloc>(std::move(buf)); } } @@ -99,7 +107,7 @@ ByteBuffer::copyBuffer(const char* buffer, uint32_t len) if (buffer && len) { Alloc newBuf = Alloc::alloc(len); memcpy(newBuf.get(), buffer, len); - return ByteBuffer(std::move(newBuf), len); + return ByteBuffer(std::make_unique<Alloc>(std::move(newBuf)), len); } else { return ByteBuffer(); } diff --git a/document/src/vespa/document/util/bytebuffer.h b/document/src/vespa/document/util/bytebuffer.h index 3f64f51a88a..1eb359e261b 100644 --- a/document/src/vespa/document/util/bytebuffer.h +++ b/document/src/vespa/document/util/bytebuffer.h @@ -46,6 +46,7 @@ public: * @param len The length of the buffer */ ByteBuffer(vespalib::alloc::Alloc buffer, uint32_t len); + ByteBuffer(std::unique_ptr<vespalib::alloc::Alloc> buffer, uint32_t len); /** * Creates a ByteBuffer object from another buffer. allocates @@ -113,7 +114,7 @@ private: const char * _buffer; uint32_t _len; uint32_t _pos; - vespalib::alloc::Alloc _ownedBuffer; + std::unique_ptr<vespalib::alloc::Alloc> _ownedBuffer; }; } // document |