aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
Diffstat (limited to 'zencore')
-rw-r--r--zencore/compactbinarybuilder.cpp5
-rw-r--r--zencore/iobuffer.cpp12
2 files changed, 13 insertions, 4 deletions
diff --git a/zencore/compactbinarybuilder.cpp b/zencore/compactbinarybuilder.cpp
index 5111504e1..1d2ba45df 100644
--- a/zencore/compactbinarybuilder.cpp
+++ b/zencore/compactbinarybuilder.cpp
@@ -436,9 +436,10 @@ CbWriter::AddNull()
void
CbWriter::AddBinary(const void* const Value, const uint64_t Size)
{
+ const size_t SizeByteCount = MeasureVarUInt(Size);
+ Data.reserve(Data.size() + 1 + SizeByteCount + Size);
BeginField();
- const uint32_t SizeByteCount = MeasureVarUInt(Size);
- const int64_t SizeOffset = Data.size();
+ const size_t SizeOffset = Data.size();
Data.resize(Data.size() + SizeByteCount);
WriteVarUInt(Size, Data.data() + SizeOffset);
Data.insert(Data.end(), static_cast<const uint8_t*>(Value), static_cast<const uint8_t*>(Value) + Size);
diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp
index 8a3ab8427..c069aa0f1 100644
--- a/zencore/iobuffer.cpp
+++ b/zencore/iobuffer.cpp
@@ -226,7 +226,15 @@ IoBufferExtendedCore::~IoBufferExtendedCore()
m_DataPtr = nullptr;
}
-static RwLock g_MappingLock;
+static RwLock g_MappingLock[0x40];
+
+static RwLock&
+MappingLockForInstance(const IoBufferExtendedCore* instance)
+{
+ intptr_t base = (intptr_t)instance;
+ size_t lock_index = ((base >> 8) ^ (base >> 16)) & 0x3f;
+ return g_MappingLock[lock_index];
+}
void
IoBufferExtendedCore::Materialize() const
@@ -237,7 +245,7 @@ IoBufferExtendedCore::Materialize() const
if (m_Flags.load(std::memory_order_acquire) & kIsMaterialized)
return;
- RwLock::ExclusiveLockScope _(g_MappingLock);
+ RwLock::ExclusiveLockScope _(MappingLockForInstance(this));
// Someone could have gotten here first
// We can use memory_order_relaxed on this load because the mutex has already provided the fence