diff options
| author | babenko <[email protected]> | 2022-12-04 19:31:32 +0300 | 
|---|---|---|
| committer | babenko <[email protected]> | 2022-12-04 19:31:32 +0300 | 
| commit | 3680ca61e6e893b6ddbba096616c807efd3d7c2b (patch) | |
| tree | 0e46d6e15ed4cec31b2fe9c7b8d8d89c2305b728 /library/cpp | |
| parent | 7adf7eaadc3fe5a045969aa96ef3abe6ba2bf3a3 (diff) | |
Add TSharedRefArray::ToString
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/yt/memory/ref.cpp | 21 | ||||
| -rw-r--r-- | library/cpp/yt/memory/ref.h | 1 | 
2 files changed, 22 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/ref.cpp b/library/cpp/yt/memory/ref.cpp index aff7baedd3a..d167247c201 100644 --- a/library/cpp/yt/memory/ref.cpp +++ b/library/cpp/yt/memory/ref.cpp @@ -332,6 +332,27 @@ std::vector<TSharedRef> TSharedRefArray::ToVector() const      return std::vector<TSharedRef>(Begin(), End());  } +TString TSharedRefArray::ToString() const +{ +    if (!Impl_) { +        return {}; +    } + +    TString result; +    size_t size = 0; +    for (const auto& part : *this) { +        size += part.size(); +    } +    result.ReserveAndResize(size); +    char* ptr = result.begin(); +    for (const auto& part : *this) { +        size += part.size(); +        ::memcpy(ptr, part.begin(), part.size()); +        ptr += part.size(); +    } +    return result; +} +  ////////////////////////////////////////////////////////////////////////////////  TSharedRefArrayBuilder::TSharedRefArrayBuilder( diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h index 9b01fd2dedf..78b5cf58cb0 100644 --- a/library/cpp/yt/memory/ref.h +++ b/library/cpp/yt/memory/ref.h @@ -300,6 +300,7 @@ public:      const TSharedRef* End() const;      std::vector<TSharedRef> ToVector() const; +    TString ToString() const;  private:      friend class TSharedRefArrayBuilder;  | 
