@@ -276,32 +276,30 @@ struct IContiguousChunk : TThrRefBase {
276276 */
277277 virtual TContiguousSpan GetData () const = 0;
278278
279- /* *
280- * Should give mutable access to underlying data
281- * If data is shared - data should be copied
282- * E.g. for TString str.Detach() should be used
283- * Possibly invalidates previous *GetData*() calls
284- */
285- virtual TMutableContiguousSpan GetDataMut () = 0;
286-
287279 /* *
288280 * Should give mutable access to undelying data as fast as possible
289281 * Even if data is shared this property should be ignored
290282 * E.g. in TString const_cast<char *>(str.data()) should be used
291283 * Possibly invalidates previous *GetData*() calls
292284 */
293- virtual TMutableContiguousSpan UnsafeGetDataMut () {
294- return GetDataMut ();
295- }
285+ virtual TMutableContiguousSpan UnsafeGetDataMut () = 0;
296286
297287 /* *
298- * Should return true if GetDataMut() would not copy contents when called.
288+ * Must return false if the implementation shares data
299289 */
300290 virtual bool IsPrivate () const {
301- return true ;
291+ return RefCount () == 1 ;
302292 }
303293
304294 virtual size_t GetOccupiedMemorySize () const = 0;
295+
296+
297+ /* *
298+ * Allocate new chunk and copy data into it
299+ * NOTE: The actual implementation of clonned chunk may be different
300+ */
301+
302+ virtual IContiguousChunk::TPtr Clone () = 0;
305303};
306304
307305class TRope ;
@@ -444,7 +442,7 @@ class TRcBuf {
444442 } else if constexpr (std::is_same_v<T, TString>) {
445443 return value.IsDetached ();
446444 } else if constexpr (std::is_same_v<T, IContiguousChunk::TPtr>) {
447- return value. RefCount () == 1 && value ->IsPrivate ();
445+ return value->IsPrivate ();
448446 } else {
449447 static_assert (TDependentFalse<T>);
450448 }
@@ -486,7 +484,10 @@ class TRcBuf {
486484 }
487485 return {value.mutable_data (), value.size ()};
488486 } else if constexpr (std::is_same_v<T, IContiguousChunk::TPtr>) {
489- return value->GetDataMut ();
487+ if (!value->IsPrivate ()) {
488+ value = value->Clone ();
489+ }
490+ return value->UnsafeGetDataMut ();
490491 } else {
491492 static_assert (TDependentFalse<T>, " unexpected type" );
492493 }
0 commit comments