diff options
author | Alexander Smirnov <alex@ydb.tech> | 2025-02-07 13:56:21 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2025-02-07 13:56:21 +0000 |
commit | d7e1157d756d10899104a00d009a67cf829deef3 (patch) | |
tree | 0f80eabb5c00a3880f8fe2fe94b43ab67e98ce04 /library/cpp | |
parent | 02b921de1e48aceda819779ec9f2e26024cebd96 (diff) | |
parent | f1f926eea7fcf8945c320e5688d850776dcf9d6c (diff) | |
download | ydb-d7e1157d756d10899104a00d009a67cf829deef3.tar.gz |
Merge branch 'rightlib' into merge-libs-250207-1355
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/enumbitset/enumbitset.h | 2 | ||||
-rw-r--r-- | library/cpp/yt/memory/chunked_memory_pool-inl.h | 22 |
2 files changed, 13 insertions, 11 deletions
diff --git a/library/cpp/enumbitset/enumbitset.h b/library/cpp/enumbitset/enumbitset.h index 41864c3a04f..1470a1ff2f7 100644 --- a/library/cpp/enumbitset/enumbitset.h +++ b/library/cpp/enumbitset/enumbitset.h @@ -309,7 +309,7 @@ public: static const size_t chunkSize = sizeof(typename TParent::TChunk) * 8; static const size_t numDig = chunkSize / 4; static const size_t highChunkBits = (BitsetSize + chunkSize - 1) % chunkSize + 1; - static const typename TParent::TChunk highChunkBitsMask = (typename TParent::TChunk(1) << highChunkBits) - 1; + static const typename TParent::TChunk highChunkBitsMask = (highChunkBits == chunkSize ? 0 : (typename TParent::TChunk(1) << highChunkBits)) - 1; Reset(); for (size_t prev = s.length(), n = s.length() - numDig, pos = 0; prev; n -= numDig, pos += chunkSize) { diff --git a/library/cpp/yt/memory/chunked_memory_pool-inl.h b/library/cpp/yt/memory/chunked_memory_pool-inl.h index c6ed21fbac1..68d346167f9 100644 --- a/library/cpp/yt/memory/chunked_memory_pool-inl.h +++ b/library/cpp/yt/memory/chunked_memory_pool-inl.h @@ -78,7 +78,7 @@ inline TChunkedMemoryPool::TChunkedMemoryPool( inline char* TChunkedMemoryPool::AllocateUnaligned(size_t size) { // Fast path. - if (FreeZoneEnd_ >= FreeZoneBegin_ + size) { + if (FreeZoneBegin_ && FreeZoneEnd_ >= FreeZoneBegin_ + size) { FreeZoneEnd_ -= size; Size_ += size; return FreeZoneEnd_; @@ -90,15 +90,17 @@ inline char* TChunkedMemoryPool::AllocateUnaligned(size_t size) inline char* TChunkedMemoryPool::AllocateAligned(size_t size, int align) { - // NB: This can lead to FreeZoneBegin_ >= FreeZoneEnd_ in which case the chunk is full. - FreeZoneBegin_ = AlignUp(FreeZoneBegin_, align); - - // Fast path. - if (FreeZoneBegin_ + size <= FreeZoneEnd_) { - char* result = FreeZoneBegin_; - Size_ += size; - FreeZoneBegin_ += size; - return result; + if (FreeZoneBegin_) { + // NB: This can lead to FreeZoneBegin_ >= FreeZoneEnd_ in which case the chunk is full. + FreeZoneBegin_ = AlignUp(FreeZoneBegin_, align); + + // Fast path. + if (FreeZoneBegin_ + size <= FreeZoneEnd_) { + char* result = FreeZoneBegin_; + Size_ += size; + FreeZoneBegin_ += size; + return result; + } } // Slow path. |