From a13b3697924cc08738bfad6a54007d9219893412 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 2 May 2018 21:11:49 -0500 Subject: [PATCH] [ox/buffer] Add copy constructor to NodeBuffer --- deps/ox/src/ox/ptrarith/nodebuffer.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/ptrarith/nodebuffer.hpp b/deps/ox/src/ox/ptrarith/nodebuffer.hpp index 920e1618..4ab16e7d 100644 --- a/deps/ox/src/ox/ptrarith/nodebuffer.hpp +++ b/deps/ox/src/ox/ptrarith/nodebuffer.hpp @@ -75,6 +75,8 @@ class __attribute__((packed)) NodeBuffer { public: NodeBuffer() = default; + NodeBuffer(const NodeBuffer &other); + explicit NodeBuffer(size_t size); const Iterator iterator() const; @@ -120,9 +122,11 @@ class __attribute__((packed)) NodeBuffer { */ size_t spaceNeeded(size_t size); - private: - void compact(void (*cb)(ItemPtr itemMoved)); + void compact(void (*cb)(ItemPtr itemMoved) = nullptr); + void truncate(); + + private: uint8_t *data(); }; @@ -132,6 +136,11 @@ NodeBuffer::NodeBuffer(size_t size) { m_header.size = size; } +template +NodeBuffer::NodeBuffer(const NodeBuffer &other) { + ox_memcpy(this, &other, other.size()); +} + template const typename NodeBuffer::Iterator NodeBuffer::iterator() const { return Iterator(this, firstItem()); @@ -314,6 +323,11 @@ void NodeBuffer::compact(void (*cb)(ItemPtr)) { } } +template +void NodeBuffer::truncate() { + m_header.size = m_header.bytesUsed; +} + template uint8_t *NodeBuffer::data() { return reinterpret_cast(ptr(sizeof(*this)).get());