diff options
author | innokentii <innokentii@yandex-team.com> | 2022-12-09 10:17:25 +0300 |
---|---|---|
committer | innokentii <innokentii@yandex-team.com> | 2022-12-09 10:17:25 +0300 |
commit | 216e087ea762ae7e4f19e219a18360a93adf8ae6 (patch) | |
tree | 7c8da8e9b298f1cc9307fabdb896404db757f0b3 /library | |
parent | 9323fe28059355bafc517301a3e7a00fc0367f08 (diff) | |
download | ydb-216e087ea762ae7e4f19e219a18360a93adf8ae6.tar.gz |
Rename TContiguousData to TRcBuf
rename TContiguousData to TRcBuf
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp | 2 | ||||
-rw-r--r-- | library/cpp/actors/util/rc_buf.h (renamed from library/cpp/actors/util/contiguous_data.h) | 72 | ||||
-rw-r--r-- | library/cpp/actors/util/rc_buf_backend.h (renamed from library/cpp/actors/util/contiguous_data_backend.h) | 26 | ||||
-rw-r--r-- | library/cpp/actors/util/rc_buf_ut.cpp (renamed from library/cpp/actors/util/contiguous_data_ut.cpp) | 36 | ||||
-rw-r--r-- | library/cpp/actors/util/rope.h | 76 | ||||
-rw-r--r-- | library/cpp/actors/util/rope_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/actors/util/shared_data_rope_backend.h | 2 |
7 files changed, 111 insertions, 111 deletions
diff --git a/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp b/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp index 5a4df9d736..a8c505d94d 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp +++ b/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp @@ -428,7 +428,7 @@ namespace NActors { Y_VERIFY(!Buffers.empty()); auto& buffer = Buffers.front(); const size_t bytes = Min<size_t>(recvres, buffer->GetCapacity() - FirstBufferOffset); - IncomingData.Insert(IncomingData.End(), TContiguousData{buffer, {buffer->GetBuffer() + FirstBufferOffset, bytes}}); + IncomingData.Insert(IncomingData.End(), TRcBuf{buffer, {buffer->GetBuffer() + FirstBufferOffset, bytes}}); recvres -= bytes; FirstBufferOffset += bytes; if (FirstBufferOffset == buffer->GetCapacity()) { diff --git a/library/cpp/actors/util/contiguous_data.h b/library/cpp/actors/util/rc_buf.h index 22b28d3c46..ac770e1f00 100644 --- a/library/cpp/actors/util/contiguous_data.h +++ b/library/cpp/actors/util/rc_buf.h @@ -14,7 +14,7 @@ #include <util/system/sys_alloc.h> #include "shared_data.h" -#include "contiguous_data_backend.h" +#include "rc_buf_backend.h" #ifdef KIKIMR_TRACE_CONTIGUOUS_DATA_GROW #include "shared_data_backtracing_owner.h" @@ -289,11 +289,11 @@ struct IContiguousChunk : TThrRefBase { class TRope; class TRopeArena; -class TContiguousData { +class TRcBuf { friend class TRope; friend class TRopeArena; - using TInternalBackend = NDetail::TContiguousDataInternalBackend; + using TInternalBackend = NDetail::TRcBufInternalBackend; class TBackend { enum class EType : uintptr_t { @@ -694,7 +694,7 @@ class TContiguousData { const char *Begin; // data start const char *End; // data end - explicit TContiguousData(TInternalBackend s, const char *data, size_t size) + explicit TRcBuf(TInternalBackend s, const char *data, size_t size) : Backend(std::move(s)) { Y_VERIFY(Backend.GetData().data() == nullptr || @@ -703,7 +703,7 @@ class TContiguousData { End = data + size; } - explicit TContiguousData(TInternalBackend s) + explicit TRcBuf(TInternalBackend s) : Backend(std::move(s)) { auto span = Backend.GetData(); @@ -711,8 +711,8 @@ class TContiguousData { End = Begin + span.size(); } - TContiguousData(TOwnedSlice, const char *data, size_t size, const TContiguousData& from) - : TContiguousData(from.Backend, {data, size}) + TRcBuf(TOwnedSlice, const char *data, size_t size, const TRcBuf& from) + : TRcBuf(from.Backend, {data, size}) { Y_VERIFY(data >= from.GetData()); Y_VERIFY(data < from.GetData() + from.GetSize()); @@ -720,8 +720,8 @@ class TContiguousData { Backend.UpdateCookiesUnsafe(Begin, End); } - TContiguousData(TOwnedSlice, const char *begin, const char *end, const TContiguousData& from) - : TContiguousData(OwnedSlice, begin, end - begin, from) + TRcBuf(TOwnedSlice, const char *begin, const char *end, const TRcBuf& from) + : TRcBuf(OwnedSlice, begin, end - begin, from) {} public: @@ -738,19 +738,19 @@ public: // SaveAllocs, // Move data if there is enough space in (headroom + size + tailroom) }; - TContiguousData() + TRcBuf() : Begin(nullptr) , End(nullptr) {} template<typename T> - TContiguousData(T&& backend, const TContiguousSpan& data) + TRcBuf(T&& backend, const TContiguousSpan& data) : Backend(std::forward<T>(backend)) , Begin(data.data()) , End(Begin + data.size()) {} - explicit TContiguousData(TString s) + explicit TRcBuf(TString s) : Backend(std::move(s)) { auto span = Backend.GetData(); @@ -758,7 +758,7 @@ public: End = Begin + span.size(); } - explicit TContiguousData(NActors::TSharedData s) + explicit TRcBuf(NActors::TSharedData s) : Backend(std::move(s)) { auto span = Backend.GetData(); @@ -766,63 +766,63 @@ public: End = Begin + span.size(); } - TContiguousData(IContiguousChunk::TPtr backend) - : TContiguousData(backend, backend->GetData()) + TRcBuf(IContiguousChunk::TPtr backend) + : TRcBuf(backend, backend->GetData()) {} - TContiguousData(TSlice, const char *data, size_t size, const TContiguousData& from) - : TContiguousData(from.Backend, {data, size}) + TRcBuf(TSlice, const char *data, size_t size, const TRcBuf& from) + : TRcBuf(from.Backend, {data, size}) { Y_VERIFY(data >= from.GetData()); Y_VERIFY(data < from.GetData() + from.GetSize()); Y_VERIFY(data + size <= from.GetData() + from.GetSize()); } - TContiguousData(TSlice, const char *begin, const char *end, const TContiguousData& from) - : TContiguousData(Slice, begin, end - begin, from) + TRcBuf(TSlice, const char *begin, const char *end, const TRcBuf& from) + : TRcBuf(Slice, begin, end - begin, from) {} - TContiguousData(const TContiguousData& other) + TRcBuf(const TRcBuf& other) : Backend(other.Backend) , Begin(other.Begin) , End(other.End) {} - TContiguousData(TContiguousData&& other) + TRcBuf(TRcBuf&& other) : Backend(std::move(other.Backend)) , Begin(other.Begin) , End(other.End) {} - TContiguousData& operator =(const TContiguousData&) = default; - TContiguousData& operator =(TContiguousData&&) = default; + TRcBuf& operator =(const TRcBuf&) = default; + TRcBuf& operator =(TRcBuf&&) = default; - static TContiguousData Uninitialized(size_t size, size_t headroom = 0, size_t tailroom = 0) + static TRcBuf Uninitialized(size_t size, size_t headroom = 0, size_t tailroom = 0) { if (size == 0) { - return TContiguousData(); + return TRcBuf(); } if (headroom == 0 && tailroom == 0) { TInternalBackend res = TInternalBackend::Uninitialized(size); - return TContiguousData( + return TRcBuf( OwnedSlice, res.data(), res.data() + res.size(), - TContiguousData(res)); + TRcBuf(res)); } TInternalBackend res = TInternalBackend::Uninitialized(size, headroom, tailroom); - return TContiguousData(res, res.data() + headroom, size); + return TRcBuf(res, res.data() + headroom, size); } - static TContiguousData Copy(TContiguousSpan data, size_t headroom = 0, size_t tailroom = 0) { - TContiguousData res = Uninitialized(data.size(), headroom, tailroom); + static TRcBuf Copy(TContiguousSpan data, size_t headroom = 0, size_t tailroom = 0) { + TRcBuf res = Uninitialized(data.size(), headroom, tailroom); std::memcpy(res.UnsafeGetDataMut(), data.GetData(), data.GetSize()); return res; } - static TContiguousData Copy(const char* data, size_t size, size_t headroom = 0, size_t tailroom = 0) { + static TRcBuf Copy(const char* data, size_t size, size_t headroom = 0, size_t tailroom = 0) { return Copy({data, size}, headroom, tailroom); } @@ -970,7 +970,7 @@ public: if (Headroom() >= size) { return; } - auto newData = TContiguousData::Uninitialized(GetSize(), size, UnsafeTailroom()); + auto newData = TRcBuf::Uninitialized(GetSize(), size, UnsafeTailroom()); if (auto data = GetData(); data) { std::memcpy(newData.UnsafeGetDataMut(), GetData(), GetSize()); } @@ -981,7 +981,7 @@ public: if (Tailroom() >= size) { return; } - auto newData = TContiguousData::Uninitialized(GetSize(), UnsafeHeadroom(), size); + auto newData = TRcBuf::Uninitialized(GetSize(), UnsafeHeadroom(), size); if (auto data = GetData(); data) { std::memcpy(newData.UnsafeGetDataMut(), GetData(), GetSize()); } @@ -992,7 +992,7 @@ public: if (Headroom() >= headroom && Tailroom() >= tailroom) { return; } - auto newData = TContiguousData::Uninitialized( + auto newData = TRcBuf::Uninitialized( GetSize(), std::max(UnsafeHeadroom(), headroom), std::max(UnsafeTailroom(), tailroom)); @@ -1010,7 +1010,7 @@ public: if (strategy == EResizeStrategy::FailOnCopy && static_cast<bool>(Backend)) { Y_FAIL("Fail on grow"); } - auto newData = TContiguousData::Uninitialized(size + GetSize(), UnsafeHeadroom() > size ? UnsafeHeadroom() - size : 0, UnsafeTailroom()); + auto newData = TRcBuf::Uninitialized(size + GetSize(), UnsafeHeadroom() > size ? UnsafeHeadroom() - size : 0, UnsafeTailroom()); if (auto data = GetData(); data) { std::memcpy(newData.UnsafeGetDataMut() + size, GetData(), GetSize()); } @@ -1027,7 +1027,7 @@ public: if (strategy == EResizeStrategy::FailOnCopy && static_cast<bool>(Backend)) { Y_FAIL("Fail on grow"); } - auto newData = TContiguousData::Uninitialized(size + GetSize(), UnsafeHeadroom(), UnsafeTailroom() > size ? UnsafeTailroom() - size : 0); + auto newData = TRcBuf::Uninitialized(size + GetSize(), UnsafeHeadroom(), UnsafeTailroom() > size ? UnsafeTailroom() - size : 0); if (auto data = GetData(); data) { std::memcpy(newData.UnsafeGetDataMut(), GetData(), GetSize()); } diff --git a/library/cpp/actors/util/contiguous_data_backend.h b/library/cpp/actors/util/rc_buf_backend.h index 9f97906114..f7089a302c 100644 --- a/library/cpp/actors/util/contiguous_data_backend.h +++ b/library/cpp/actors/util/rc_buf_backend.h @@ -11,7 +11,7 @@ namespace NDetail { -struct TContiguousDataInternalBackend { +struct TRcBufInternalBackend { public: struct TCookies { using TSelf = TCookies; @@ -41,23 +41,23 @@ private: }; public: - TContiguousDataInternalBackend() noexcept + TRcBufInternalBackend() noexcept : Data_(nullptr) , Size_(0) { } - ~TContiguousDataInternalBackend() noexcept { + ~TRcBufInternalBackend() noexcept { Release(); } - TContiguousDataInternalBackend(const TContiguousDataInternalBackend& other) noexcept + TRcBufInternalBackend(const TRcBufInternalBackend& other) noexcept : Data_(other.Data_) , Size_(other.Size_) { AddRef(); } - TContiguousDataInternalBackend(TContiguousDataInternalBackend&& other) noexcept + TRcBufInternalBackend(TRcBufInternalBackend&& other) noexcept : Data_(other.Data_) , Size_(other.Size_) { @@ -65,7 +65,7 @@ public: other.Size_ = 0; } - TContiguousDataInternalBackend& operator=(const TContiguousDataInternalBackend& other) noexcept { + TRcBufInternalBackend& operator=(const TRcBufInternalBackend& other) noexcept { if (this != &other) { Release(); Data_ = other.Data_; @@ -75,7 +75,7 @@ public: return *this; } - TContiguousDataInternalBackend& operator=(TContiguousDataInternalBackend&& other) noexcept { + TRcBufInternalBackend& operator=(TRcBufInternalBackend&& other) noexcept { if (this != &other) { Release(); Data_ = other.Data_; @@ -105,7 +105,7 @@ public: */ char* Detach() { if (IsShared()) { - *this = TContiguousDataInternalBackend::Copy(data(), size()); + *this = TRcBufInternalBackend::Copy(data(), size()); } return Data_; } @@ -129,8 +129,8 @@ public: /** * Attach to pre-allocated data with a preceding THeader */ - static TContiguousDataInternalBackend AttachUnsafe(char* data, size_t size) noexcept { - TContiguousDataInternalBackend result; + static TRcBufInternalBackend AttachUnsafe(char* data, size_t size) noexcept { + TRcBufInternalBackend result; result.Data_ = data; result.Size_ = size; return result; @@ -139,7 +139,7 @@ public: /** * Make uninitialized buffer of the specified size */ - static TContiguousDataInternalBackend Uninitialized(size_t size, size_t headroom = 0, size_t tailroom = 0) { + static TRcBufInternalBackend Uninitialized(size_t size, size_t headroom = 0, size_t tailroom = 0) { size_t fullSize = checkedSum(size, checkedSum(headroom, tailroom)); return AttachUnsafe(Allocate(size, headroom, tailroom), fullSize); } @@ -147,8 +147,8 @@ public: /** * Make a copy of the specified data */ - static TContiguousDataInternalBackend Copy(const void* data, size_t size) { - TContiguousDataInternalBackend result = Uninitialized(size); + static TRcBufInternalBackend Copy(const void* data, size_t size) { + TRcBufInternalBackend result = Uninitialized(size); if (size) { ::memcpy(result.Data(), data, size); } diff --git a/library/cpp/actors/util/contiguous_data_ut.cpp b/library/cpp/actors/util/rc_buf_ut.cpp index 6d7c698879..9b8af6421d 100644 --- a/library/cpp/actors/util/contiguous_data_ut.cpp +++ b/library/cpp/actors/util/rc_buf_ut.cpp @@ -1,13 +1,13 @@ -#include "contiguous_data.h" +#include "rc_buf.h" #include "ut_helpers.h" #include "rope.h" #include <library/cpp/testing/unittest/registar.h> #include <util/random/random.h> -Y_UNIT_TEST_SUITE(TContiguousData) { +Y_UNIT_TEST_SUITE(TRcBuf) { Y_UNIT_TEST(TypeSize) { - UNIT_ASSERT_EQUAL(sizeof(TContiguousData), 4 * sizeof(uintptr_t)); + UNIT_ASSERT_EQUAL(sizeof(TRcBuf), 4 * sizeof(uintptr_t)); } Y_UNIT_TEST(CrossCompare) { @@ -19,8 +19,8 @@ Y_UNIT_TEST_SUITE(TContiguousData) { const TContiguousSpan constSpan(str); TMutableContiguousSpan mutableSpan(const_cast<char*>(str.data()), str.size()); const TMutableContiguousSpan constMutableSpan(const_cast<char*>(str.data()), str.size()); - TContiguousData data(str); - const TContiguousData constData(str); + TRcBuf data(str); + const TRcBuf constData(str); TArrayRef<char> arrRef(const_cast<char*>(str.data()), str.size()); const TArrayRef<char> constArrRef(const_cast<char*>(str.data()), str.size()); TArrayRef<const char> arrConstRef(const_cast<char*>(str.data()), str.size()); @@ -51,8 +51,8 @@ Y_UNIT_TEST_SUITE(TContiguousData) { } Y_UNIT_TEST(Detach) { - TContiguousData data = TContiguousData::Copy(TString("test")); - TContiguousData data2 = data; + TRcBuf data = TRcBuf::Copy(TString("test")); + TRcBuf data2 = data; char* res = data2.Detach(); UNIT_ASSERT_UNEQUAL(data.GetData(), data2.GetData()); UNIT_ASSERT_EQUAL(res, data2.GetData()); @@ -61,7 +61,7 @@ Y_UNIT_TEST_SUITE(TContiguousData) { } Y_UNIT_TEST(Resize) { - TContiguousData data = TContiguousData::Uninitialized(10, 20, 30); + TRcBuf data = TRcBuf::Uninitialized(10, 20, 30); UNIT_ASSERT_EQUAL(data.size(), 10); UNIT_ASSERT_EQUAL(data.Headroom(), 20); UNIT_ASSERT_EQUAL(data.Tailroom(), 30); @@ -94,8 +94,8 @@ Y_UNIT_TEST_SUITE(TContiguousData) { } Y_UNIT_TEST(ResizeUnshare) { - TContiguousData data = TContiguousData::Uninitialized(10, 20, 30); - TContiguousData otherData(data); + TRcBuf data = TRcBuf::Uninitialized(10, 20, 30); + TRcBuf otherData(data); UNIT_ASSERT_EQUAL(data.data(), otherData.data()); UNIT_ASSERT_EQUAL(data.size(), 10); UNIT_ASSERT_EQUAL(data.Headroom(), 20); @@ -127,13 +127,13 @@ Y_UNIT_TEST_SUITE(TContiguousData) { } Y_UNIT_TEST(Trim) { - TContiguousData data = TContiguousData::Uninitialized(10, 20, 30); - TContiguousData otherData(data); + TRcBuf data = TRcBuf::Uninitialized(10, 20, 30); + TRcBuf otherData(data); otherData.TrimBack(5); UNIT_ASSERT_EQUAL(data.data(), otherData.data()); UNIT_ASSERT_EQUAL(otherData.Headroom(), 20); UNIT_ASSERT_EQUAL(otherData.Tailroom(), 0); - TContiguousData otherData2(data); + TRcBuf otherData2(data); otherData2.TrimBack(2); otherData2.TrimFront(1); UNIT_ASSERT_EQUAL(data.data() + 1, otherData2.data()); @@ -150,7 +150,7 @@ Y_UNIT_TEST_SUITE(TContiguousData) { UNIT_ASSERT_UNEQUAL(data.data() + 7, otherData.data()); otherData2.GrowBack(1); UNIT_ASSERT_UNEQUAL(data.data() + 6, otherData2.data()); - data = TContiguousData::Uninitialized(10); + data = TRcBuf::Uninitialized(10); otherData = data; data.TrimBack(5); UNIT_ASSERT_EQUAL(data.data(), otherData.data()); @@ -158,15 +158,15 @@ Y_UNIT_TEST_SUITE(TContiguousData) { } Y_UNIT_TEST(SliceUnshare) { - TContiguousData data = TContiguousData::Uninitialized(10, 20, 30); - TContiguousData otherData(TContiguousData::Slice, data.data() + 1, data.size() - 2, data); + TRcBuf data = TRcBuf::Uninitialized(10, 20, 30); + TRcBuf otherData(TRcBuf::Slice, data.data() + 1, data.size() - 2, data); UNIT_ASSERT_EQUAL(otherData.Headroom(), 0); UNIT_ASSERT_EQUAL(otherData.Tailroom(), 0); } Y_UNIT_TEST(Reserve) { - TContiguousData data = TContiguousData::Copy("test", 4, 5, 6); - TContiguousData data2 = data; + TRcBuf data = TRcBuf::Copy("test", 4, 5, 6); + TRcBuf data2 = data; data.reserve(1); data.ReserveTailroom(6); UNIT_ASSERT_EQUAL(data.GetData(), data2.GetData()); diff --git a/library/cpp/actors/util/rope.h b/library/cpp/actors/util/rope.h index 2b2b2df19d..a0e38535a6 100644 --- a/library/cpp/actors/util/rope.h +++ b/library/cpp/actors/util/rope.h @@ -13,7 +13,7 @@ //#include "rope_cont_list.h" //#include "rope_cont_deque.h" -#include "contiguous_data.h" +#include "rc_buf.h" class TRopeAlignedBuffer : public IContiguousChunk { static constexpr size_t Alignment = 16; @@ -102,7 +102,7 @@ struct always_false : std::false_type {}; class TRope { friend class TRopeArena; - using TChunkList = NRopeDetails::TChunkList<TContiguousData>; + using TChunkList = NRopeDetails::TChunkList<TRcBuf>; private: // we use list here to store chain items as we have to keep valid iterators when erase/insert operations are invoked; @@ -310,13 +310,13 @@ private: return Iter; } - const TContiguousData& GetChunk() const { + const TRcBuf& GetChunk() const { CheckValid(); return *Iter; } template<bool Mut = !IsConst, std::enable_if_t<Mut, bool> = true> - TContiguousData& GetChunk() { + TRcBuf& GetChunk() { CheckValid(); return *Iter; } @@ -354,7 +354,7 @@ public: TRope() = default; TRope(const TRope& rope) = default; - TRope(const TContiguousData& data) { + TRope(const TRcBuf& data) { if(!data.HasBuffer()) { return; } @@ -362,7 +362,7 @@ public: Chain.PutToEnd(data); } - TRope(TContiguousData&& data) { + TRope(TRcBuf&& data) { if(!data.HasBuffer()) { return; } @@ -407,13 +407,13 @@ public: while (begin.Iter != end.Iter) { const size_t size = begin.ContiguousSize(); - Chain.PutToEnd(TContiguousData::Slice, begin.ContiguousData(), size, begin.GetChunk()); + Chain.PutToEnd(TRcBuf::Slice, begin.ContiguousData(), size, begin.GetChunk()); begin.AdvanceToNextContiguousBlock(); Size += size; } if (begin != end && end.PointsToChunkMiddle()) { - Chain.PutToEnd(TContiguousData::Slice, begin.Ptr, end.Ptr, begin.GetChunk()); + Chain.PutToEnd(TRcBuf::Slice, begin.Ptr, end.Ptr, begin.GetChunk()); Size += end.Ptr - begin.Ptr; } } @@ -534,7 +534,7 @@ public: return; } } - dest->Chain.PutToEnd(TContiguousData::Slice, first->Begin, first->Begin + num, *first); + dest->Chain.PutToEnd(TRcBuf::Slice, first->Begin, first->Begin + num, *first); first->Begin += num; } } @@ -552,14 +552,14 @@ public: // check if we have to split the block if (pos.PointsToChunkMiddle()) { - pos.Iter = Chain.InsertBefore(pos.Iter, TContiguousData::Slice, pos->Begin, pos.Ptr, pos.GetChunk()); + pos.Iter = Chain.InsertBefore(pos.Iter, TRcBuf::Slice, pos->Begin, pos.Ptr, pos.GetChunk()); ++pos.Iter; pos->Begin = pos.Ptr; } // perform glueing if possible - TContiguousData *ropeLeft = &rope.Chain.GetFirstChunk(); - TContiguousData *ropeRight = &rope.Chain.GetLastChunk(); + TRcBuf *ropeLeft = &rope.Chain.GetFirstChunk(); + TRcBuf *ropeRight = &rope.Chain.GetLastChunk(); bool gluedLeft = false, gluedRight = false; if (pos.Iter != Chain.begin()) { // glue left part whenever possible // obtain iterator to previous chunk @@ -600,7 +600,7 @@ public: while (len) { Y_VERIFY_DEBUG(Chain); - TContiguousData& item = Chain.GetFirstChunk(); + TRcBuf& item = Chain.GetFirstChunk(); const size_t itemSize = item.GetSize(); if (len >= itemSize) { Chain.EraseFront(); @@ -620,7 +620,7 @@ public: while (len) { Y_VERIFY_DEBUG(Chain); - TContiguousData& item = Chain.GetLastChunk(); + TRcBuf& item = Chain.GetLastChunk(); const size_t itemSize = item.GetSize(); if (len >= itemSize) { Chain.EraseBack(); @@ -734,7 +734,7 @@ public: void Compact(size_t headroom = 0, size_t tailroom = 0) { if(!IsContiguous()) { // TODO(innokentii): use better container, when most outer users stop use TString - TContiguousData res = TContiguousData::Uninitialized(GetSize(), headroom, tailroom); + TRcBuf res = TRcBuf::Uninitialized(GetSize(), headroom, tailroom); Begin().ExtractPlainDataAndAdvance(res.UnsafeGetDataMut(), res.size()); Erase(Begin(), End()); Insert(End(), TRope(res)); @@ -743,7 +743,7 @@ public: static TRope Uninitialized(size_t size) { - TContiguousData res = TContiguousData::Uninitialized(size); + TRcBuf res = TRcBuf::Uninitialized(size); return TRope(res); } @@ -796,12 +796,12 @@ public: return s.Str(); } - explicit operator TContiguousData() { + explicit operator TRcBuf() { if(GetSize() == 0) { - return TContiguousData(); + return TRcBuf(); } Compact(); - return TContiguousData(Begin().GetChunk()); + return TRcBuf(Begin().GetChunk()); } friend bool operator==(const TRope& x, const TRope& y) { return Compare(x, y) == 0; } @@ -826,19 +826,19 @@ public: friend bool operator>=(const TContiguousSpan& x, const TRope& y) { return Compare(x, y) >= 0; } // FIXME(innokentii) temporary hack - friend bool operator==(const TRope& x, const TContiguousData& y) { return Compare(x, y.GetContiguousSpan()) == 0; } - friend bool operator!=(const TRope& x, const TContiguousData& y) { return Compare(x, y.GetContiguousSpan()) != 0; } - friend bool operator< (const TRope& x, const TContiguousData& y) { return Compare(x, y.GetContiguousSpan()) < 0; } - friend bool operator<=(const TRope& x, const TContiguousData& y) { return Compare(x, y.GetContiguousSpan()) <= 0; } - friend bool operator> (const TRope& x, const TContiguousData& y) { return Compare(x, y.GetContiguousSpan()) > 0; } - friend bool operator>=(const TRope& x, const TContiguousData& y) { return Compare(x, y.GetContiguousSpan()) >= 0; } + friend bool operator==(const TRope& x, const TRcBuf& y) { return Compare(x, y.GetContiguousSpan()) == 0; } + friend bool operator!=(const TRope& x, const TRcBuf& y) { return Compare(x, y.GetContiguousSpan()) != 0; } + friend bool operator< (const TRope& x, const TRcBuf& y) { return Compare(x, y.GetContiguousSpan()) < 0; } + friend bool operator<=(const TRope& x, const TRcBuf& y) { return Compare(x, y.GetContiguousSpan()) <= 0; } + friend bool operator> (const TRope& x, const TRcBuf& y) { return Compare(x, y.GetContiguousSpan()) > 0; } + friend bool operator>=(const TRope& x, const TRcBuf& y) { return Compare(x, y.GetContiguousSpan()) >= 0; } - friend bool operator==(const TContiguousData& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) == 0; } - friend bool operator!=(const TContiguousData& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) != 0; } - friend bool operator< (const TContiguousData& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) < 0; } - friend bool operator<=(const TContiguousData& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) <= 0; } - friend bool operator> (const TContiguousData& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) > 0; } - friend bool operator>=(const TContiguousData& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) >= 0; } + friend bool operator==(const TRcBuf& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) == 0; } + friend bool operator!=(const TRcBuf& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) != 0; } + friend bool operator< (const TRcBuf& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) < 0; } + friend bool operator<=(const TRcBuf& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) <= 0; } + friend bool operator> (const TRcBuf& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) > 0; } + friend bool operator>=(const TRcBuf& x, const TRope& y) { return Compare(x.GetContiguousSpan(), y) >= 0; } private: @@ -852,9 +852,9 @@ private: return; } - auto addBlock = [&](const TContiguousData& from, const char *begin, const char *end) { + auto addBlock = [&](const TRcBuf& from, const char *begin, const char *end) { if (target) { - target->Chain.PutToEnd(TContiguousData::Slice, begin, end, from); + target->Chain.PutToEnd(TRcBuf::Slice, begin, end, from); target->Size += end - begin; } Size -= end - begin; @@ -863,12 +863,12 @@ private: // consider special case -- when begin and end point to the same block; in this case we have to split up this // block into two parts if (begin.Iter == end.Iter) { - TContiguousData chunkToSplit = begin.GetChunk(); + TRcBuf chunkToSplit = begin.GetChunk(); addBlock(chunkToSplit, begin.Ptr, end.Ptr); const char *firstChunkBegin = begin.PointsToChunkMiddle() ? begin->Begin : nullptr; begin->Begin = end.Ptr; // this affects both begin and end iterator pointed values if (firstChunkBegin) { - Chain.InsertBefore(begin.Iter, TContiguousData::Slice, firstChunkBegin, begin.Ptr, chunkToSplit); + Chain.InsertBefore(begin.Iter, TRcBuf::Slice, firstChunkBegin, begin.Ptr, chunkToSplit); } } else { // check the first iterator -- if it starts not from the begin of the block, we have to adjust end of the @@ -950,7 +950,7 @@ public: return Size; } - void AccountChunk(const TContiguousData& chunk) { + void AccountChunk(const TRcBuf& chunk) { if (AccountedBuffers.insert(chunk.Backend.UniqueId()).second) { Size += chunk.GetOccupiedMemorySize(); } @@ -1083,7 +1083,7 @@ public: inline TRope TRope::CopySpaceOptimized(TRope&& origin, size_t worstRatioPer1k, TRopeArena& arena) { TRope res; - for (TContiguousData& chunk : origin.Chain) { + for (TRcBuf& chunk : origin.Chain) { size_t ratio = chunk.GetSize() * 1024 / chunk.GetOccupiedMemorySize(); if (ratio < 1024 - worstRatioPer1k) { res.Insert(res.End(), arena.CreateRope(chunk.Begin, chunk.GetSize())); @@ -1093,7 +1093,7 @@ inline TRope TRope::CopySpaceOptimized(TRope&& origin, size_t worstRatioPer1k, T } res.Size = origin.Size; origin = TRope(); - for (const TContiguousData& chunk : res.Chain) { + for (const TRcBuf& chunk : res.Chain) { arena.AccountChunk(chunk); } return res; diff --git a/library/cpp/actors/util/rope_ut.cpp b/library/cpp/actors/util/rope_ut.cpp index 5ca02d8043..ba7c38044f 100644 --- a/library/cpp/actors/util/rope_ut.cpp +++ b/library/cpp/actors/util/rope_ut.cpp @@ -140,11 +140,11 @@ Y_UNIT_TEST_SUITE(TRope) { Y_UNIT_TEST(ContiguousDataInterop) { TString string = "Some long-long text needed for not sharing data and testing"; - TContiguousData data(string); + TRcBuf data(string); UNIT_ASSERT_EQUAL(data.UnsafeGetDataMut(), &(*string.cbegin())); TRope rope(data); // check operator TRope UNIT_ASSERT_EQUAL(rope.UnsafeGetContiguousSpanMut().data(), &(*string.cbegin())); - TContiguousData otherData(rope); + TRcBuf otherData(rope); UNIT_ASSERT_EQUAL(otherData.UnsafeGetDataMut(), &(*string.cbegin())); TString extractedBack = otherData.ExtractUnderlyingContainerOrCopy<TString>(); UNIT_ASSERT_EQUAL(extractedBack.data(), &(*string.cbegin())); @@ -159,8 +159,8 @@ Y_UNIT_TEST_SUITE(TRope) { const TContiguousSpan constSpan(str); TMutableContiguousSpan mutableSpan(const_cast<char*>(str.data()), str.size()); const TMutableContiguousSpan constMutableSpan(const_cast<char*>(str.data()), str.size()); - TContiguousData data(str); - const TContiguousData constData(str); + TRcBuf data(str); + const TRcBuf constData(str); TArrayRef<char> arrRef(const_cast<char*>(str.data()), str.size()); const TArrayRef<char> constArrRef(const_cast<char*>(str.data()), str.size()); TArrayRef<const char> arrConstRef(const_cast<char*>(str.data()), str.size()); diff --git a/library/cpp/actors/util/shared_data_rope_backend.h b/library/cpp/actors/util/shared_data_rope_backend.h index f6f2b2a49a..2abfcf5584 100644 --- a/library/cpp/actors/util/shared_data_rope_backend.h +++ b/library/cpp/actors/util/shared_data_rope_backend.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/util/contiguous_data.h> +#include <library/cpp/actors/util/rc_buf.h> #include "shared_data.h" |