aboutsummaryrefslogtreecommitdiff
path: root/src/zencore
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-05-30 14:44:34 +0200
committerGitHub Enterprise <[email protected]>2024-05-30 14:44:34 +0200
commit8ce1dc72cce381b2adae256504331f2e8893f262 (patch)
treedf5ab56ce8cdf0f6664ed611f4cf1fb848718ea6 /src/zencore
parentworkspaces review feedback (diff)
downloadzen-8ce1dc72cce381b2adae256504331f2e8893f262.tar.xz
zen-8ce1dc72cce381b2adae256504331f2e8893f262.zip
cache optimizations (#88)
* message formatting optimizations * bump iostorecompression small value threshold to 1MB
Diffstat (limited to 'src/zencore')
-rw-r--r--src/zencore/compactbinarypackage.cpp4
-rw-r--r--src/zencore/include/zencore/compactbinarypackage.h4
-rw-r--r--src/zencore/include/zencore/compositebuffer.h13
3 files changed, 17 insertions, 4 deletions
diff --git a/src/zencore/compactbinarypackage.cpp b/src/zencore/compactbinarypackage.cpp
index 4d4e0951e..0117b326e 100644
--- a/src/zencore/compactbinarypackage.cpp
+++ b/src/zencore/compactbinarypackage.cpp
@@ -261,7 +261,7 @@ CbAttachment::GetHash() const
return Hash;
}
-CompositeBuffer
+const CompositeBuffer&
CbAttachment::AsCompositeBinary() const
{
if (const CompositeBuffer* BinValue = std::get_if<CompositeBuffer>(&Value))
@@ -283,7 +283,7 @@ CbAttachment::AsBinary() const
return {};
}
-CompressedBuffer
+const CompressedBuffer&
CbAttachment::AsCompressedBinary() const
{
if (const CompressedBuffer* CompValue = std::get_if<CompressedBuffer>(&Value))
diff --git a/src/zencore/include/zencore/compactbinarypackage.h b/src/zencore/include/zencore/compactbinarypackage.h
index 4a6bca67a..fe4a60a30 100644
--- a/src/zencore/include/zencore/compactbinarypackage.h
+++ b/src/zencore/include/zencore/compactbinarypackage.h
@@ -77,10 +77,10 @@ public:
ZENCORE_API [[nodiscard]] SharedBuffer AsBinary() const;
/** Access the attachment as raw binary. Defaults to a null buffer on error. */
- ZENCORE_API [[nodiscard]] CompositeBuffer AsCompositeBinary() const;
+ ZENCORE_API [[nodiscard]] const CompositeBuffer& AsCompositeBinary() const;
/** Access the attachment as compressed binary. Defaults to a null buffer if the attachment is null. */
- ZENCORE_API [[nodiscard]] CompressedBuffer AsCompressedBinary() const;
+ ZENCORE_API [[nodiscard]] const CompressedBuffer& AsCompressedBinary() const;
/** Access the attachment as compact binary. Defaults to a field iterator with no value on error. */
ZENCORE_API [[nodiscard]] CbObject AsObject() const;
diff --git a/src/zencore/include/zencore/compositebuffer.h b/src/zencore/include/zencore/compositebuffer.h
index 1b6944fc0..b435c5e74 100644
--- a/src/zencore/include/zencore/compositebuffer.h
+++ b/src/zencore/include/zencore/compositebuffer.h
@@ -123,19 +123,32 @@ private:
static inline size_t GetBufferCount(const CompositeBuffer& Buffer) { return Buffer.m_Segments.size(); }
inline void AppendBuffers(const CompositeBuffer& Buffer)
{
+ m_Segments.reserve(m_Segments.size() + Buffer.m_Segments.size());
m_Segments.insert(m_Segments.end(), begin(Buffer.m_Segments), end(Buffer.m_Segments));
}
inline void AppendBuffers(CompositeBuffer&& Buffer) { AppendBuffers(std::move(Buffer.m_Segments)); }
static inline size_t GetBufferCount(const SharedBuffer&) { return 1; }
+ static inline size_t GetBufferCount(const IoBuffer&) { return 1; }
inline void AppendBuffers(const SharedBuffer& Buffer) { m_Segments.push_back(Buffer); }
inline void AppendBuffers(SharedBuffer&& Buffer) { m_Segments.push_back(std::move(Buffer)); }
+ inline void AppendBuffers(IoBuffer&& Buffer) { m_Segments.push_back(SharedBuffer(std::move(Buffer))); }
static inline size_t GetBufferCount(std::vector<SharedBuffer>&& Container) { return Container.size(); }
+ static inline size_t GetBufferCount(std::vector<IoBuffer>&& Container) { return Container.size(); }
inline void AppendBuffers(std::vector<SharedBuffer>&& Container)
{
+ m_Segments.reserve(m_Segments.size() + Container.size());
m_Segments.insert(m_Segments.end(), std::make_move_iterator(Container.begin()), std::make_move_iterator(Container.end()));
}
+ inline void AppendBuffers(std::vector<IoBuffer>&& Container)
+ {
+ m_Segments.reserve(m_Segments.size() + Container.size());
+ for (IoBuffer& Buffer : Container)
+ {
+ m_Segments.emplace_back(SharedBuffer(std::move(Buffer)));
+ }
+ }
private:
std::vector<SharedBuffer> m_Segments;