aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-05-05 11:03:30 +0300
committerbabenko <babenko@yandex-team.com>2024-05-05 11:11:03 +0300
commit9371341c95de0704c65d18ee6137b0873257ea80 (patch)
tree3b0416068988fffc75de4cd9cb3effd44b8cd8fa
parent878465276c7236ff9b42f47ebe8ba9294bca469a (diff)
downloadydb-9371341c95de0704c65d18ee6137b0873257ea80.tar.gz
Fix ASAN issues in GetTlsScratchBuffer
c2cf2ec6852cbccda74fe6f6de74283db553a809
-rw-r--r--library/cpp/yt/memory/tls_scratch-inl.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/library/cpp/yt/memory/tls_scratch-inl.h b/library/cpp/yt/memory/tls_scratch-inl.h
index 6984fe755b..0b4ef29bea 100644
--- a/library/cpp/yt/memory/tls_scratch-inl.h
+++ b/library/cpp/yt/memory/tls_scratch-inl.h
@@ -6,6 +6,8 @@
#include <library/cpp/yt/misc/tls.h>
+#include <util/generic/bitops.h>
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
@@ -13,13 +15,14 @@ namespace NYT {
template <class T>
YT_PREVENT_TLS_CACHING TMutableRange<T> GetTlsScratchBuffer(size_t size)
{
- // This is a workround for std::vector<bool>.
- using TBoxed = std::array<T, 1>;
- thread_local std::vector<TBoxed> tlsVector;
- tlsVector.reserve(size);
- auto range = TMutableRange(reinterpret_cast<T*>(tlsVector.data()), size);
- std::fill(range.begin(), range.end(), T());
- return range;
+ thread_local std::unique_ptr<T[]> scratchBuffer;
+ thread_local size_t scratchBufferSize;
+ if (scratchBufferSize < size) {
+ scratchBufferSize = FastClp2(size);
+ scratchBuffer = std::unique_ptr<T[]>(new T[scratchBufferSize]);
+ }
+ std::fill(scratchBuffer.get(), scratchBuffer.get() + size, T());
+ return TMutableRange(scratchBuffer.get(), size);
}
////////////////////////////////////////////////////////////////////////////////