diff --git a/csharp/src/Google.Protobuf/ByteString.cs b/csharp/src/Google.Protobuf/ByteString.cs index 4d75ff9dfa88..2619be5bef2d 100644 --- a/csharp/src/Google.Protobuf/ByteString.cs +++ b/csharp/src/Google.Protobuf/ByteString.cs @@ -58,7 +58,7 @@ public sealed class ByteString : IEnumerable, IEquatable private readonly ReadOnlyMemory bytes; /// - /// Internal use only. Ensure that the provided array is not mutated and belongs to this instance. + /// Internal use only. Ensure that the provided memory is not mutated and belongs to this instance. /// internal static ByteString AttachBytes(ReadOnlyMemory bytes) { @@ -66,7 +66,7 @@ internal static ByteString AttachBytes(ReadOnlyMemory bytes) } /// - /// Constructs a new ByteString from the given byte array. The array is + /// Constructs a new ByteString from the given memory. The memory is /// *not* copied, and must not be modified after this constructor is called. /// private ByteString(ReadOnlyMemory bytes) @@ -312,7 +312,6 @@ IEnumerator IEnumerable.GetEnumerator() public CodedInputStream CreateCodedInput() { // We trust CodedInputStream not to reveal the provided byte array or modify it - if (MemoryMarshal.TryGetArray(bytes, out ArraySegment segment) && segment.Count == bytes.Length) { // Fast path. ByteString was created with a complete array. @@ -396,24 +395,6 @@ public bool Equals(ByteString other) return this == other; } - /// - /// Used internally by CodedOutputStream to avoid creating a copy for the write - /// - internal void WriteRawBytesTo(CodedOutputStream outputStream) - { - if (MemoryMarshal.TryGetArray(bytes, out ArraySegment segment)) - { - // Fast path. ByteString was created with an array, so pass the underlying array. - outputStream.WriteRawBytes(segment.Array, segment.Offset, segment.Count); - } - else - { - // Slow path. BytesString is not an array. Convert memory and pass result to WriteRawBytes. - // TODO: Consider CodedOutputStream.WriteRawBytes(ReadOnlyMemory) overload. - outputStream.WriteRawBytes(bytes.ToArray()); - } - } - /// /// Copies the entire byte array to the destination array provided at the offset specified. ///