diff options
author | aneporada <aneporada@ydb.tech> | 2023-06-26 18:23:32 +0300 |
---|---|---|
committer | aneporada <aneporada@ydb.tech> | 2023-06-26 18:23:32 +0300 |
commit | 90298d692c83e6f459903ed532b38a0806d626fa (patch) | |
tree | 714a7446c8523bb98fa9bb926f39eea700c04691 /library/cpp/actors/util/rope.h | |
parent | b9e469eec25bfeaa903be041308020b48098c3ca (diff) | |
download | ydb-90298d692c83e6f459903ed532b38a0806d626fa.tar.gz |
Support IZeroCopyInput over TRope
initial
Diffstat (limited to 'library/cpp/actors/util/rope.h')
-rw-r--r-- | library/cpp/actors/util/rope.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/library/cpp/actors/util/rope.h b/library/cpp/actors/util/rope.h index 4aacb41089..3c65588181 100644 --- a/library/cpp/actors/util/rope.h +++ b/library/cpp/actors/util/rope.h @@ -4,6 +4,7 @@ #include <util/generic/string.h> #include <util/generic/hash_set.h> #include <util/generic/scope.h> +#include <util/stream/zerocopy.h> #include <util/stream/str.h> #include <util/system/sanitizers.h> #include <util/system/valgrind.h> @@ -1081,6 +1082,40 @@ public: } }; +class TRopeZeroCopyInput : public IZeroCopyInput { + TRope::TConstIterator Iter; + const char* Data = nullptr; + size_t Len = 0; + +private: + size_t DoNext(const void** ptr, size_t len) override { + Y_VERIFY_DEBUG(ptr); + if (Len == 0) { + if (Iter.Valid()) { + Data = Iter.ContiguousData(); + Len = Iter.ContiguousSize(); + Y_VERIFY_DEBUG(Len); + Y_VERIFY_DEBUG(Data); + ++Iter; + } else { + Data = nullptr; + } + } + + size_t chunk = std::min(Len, len); + *ptr = Data; + Data += chunk; + Len -= chunk; + return chunk; + } + +public: + explicit TRopeZeroCopyInput(TRope::TConstIterator iter) + : Iter(iter) + { + } +}; + inline TRope TRope::CopySpaceOptimized(TRope&& origin, size_t worstRatioPer1k, TRopeArena& arena) { TRope res; for (TRcBuf& chunk : origin.Chain) { |