cleanup coded output stream

pull/7576/head
Jan Tattermusch 5 years ago
parent 9039103637
commit 7bfaaba534
  1. 2
      csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs
  2. 32
      csharp/src/Google.Protobuf/CodedOutputStream.cs
  3. 6
      csharp/src/Google.Protobuf/ParsingPrimitives.cs

@ -132,7 +132,7 @@ namespace Google.Protobuf
/// </summary> /// </summary>
public static int ComputeStringSize(String value) public static int ComputeStringSize(String value)
{ {
int byteArraySize = Utf8Encoding.GetByteCount(value); int byteArraySize = WritingPrimitives.Utf8Encoding.GetByteCount(value);
return ComputeLengthSize(byteArraySize) + byteArraySize; return ComputeLengthSize(byteArraySize) + byteArraySize;
} }

@ -59,9 +59,6 @@ namespace Google.Protobuf
[SecuritySafeCritical] [SecuritySafeCritical]
public sealed partial class CodedOutputStream : IDisposable public sealed partial class CodedOutputStream : IDisposable
{ {
// "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.)
internal static readonly Encoding Utf8Encoding = Encoding.UTF8;
/// <summary> /// <summary>
/// The buffer size used by CreateInstance(Stream). /// The buffer size used by CreateInstance(Stream).
/// </summary> /// </summary>
@ -551,35 +548,6 @@ namespace Google.Protobuf
#endregion #endregion
///// <summary>
///// Encode a 32-bit value with ZigZag encoding.
///// </summary>
///// <remarks>
///// ZigZag encodes signed integers into values that can be efficiently
///// encoded with varint. (Otherwise, negative values must be
///// sign-extended to 64 bits to be varint encoded, thus always taking
///// 10 bytes on the wire.)
///// </remarks>
//internal static uint EncodeZigZag32(int n)
//{
// // Note: the right-shift must be arithmetic
// return (uint) ((n << 1) ^ (n >> 31));
//}
///// <summary>
///// Encode a 64-bit value with ZigZag encoding.
///// </summary>
///// <remarks>
///// ZigZag encodes signed integers into values that can be efficiently
///// encoded with varint. (Otherwise, negative values must be
///// sign-extended to 64 bits to be varint encoded, thus always taking
///// 10 bytes on the wire.)
///// </remarks>
//internal static ulong EncodeZigZag64(long n)
//{
// return (ulong) ((n << 1) ^ (n >> 63));
//}
//private void RefreshBuffer() //private void RefreshBuffer()
//{ //{
// if (output == null) // if (output == null)

@ -629,7 +629,7 @@ namespace Google.Protobuf
{ {
fixed (byte* sourceBytes = &MemoryMarshal.GetReference(data)) fixed (byte* sourceBytes = &MemoryMarshal.GetReference(data))
{ {
value = CodedOutputStream.Utf8Encoding.GetString(sourceBytes, length); value = WritingPrimitives.Utf8Encoding.GetString(sourceBytes, length);
} }
} }
@ -638,7 +638,7 @@ namespace Google.Protobuf
} }
#endif #endif
var decoder = CodedOutputStream.Utf8Encoding.GetDecoder(); var decoder = WritingPrimitives.Utf8Encoding.GetDecoder();
// TODO: even if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING is not supported, // TODO: even if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING is not supported,
// we could still create a string efficiently by using Utf8Encoding.GetString(byte[] bytes, int index, int count) // we could still create a string efficiently by using Utf8Encoding.GetString(byte[] bytes, int index, int count)
@ -649,7 +649,7 @@ namespace Google.Protobuf
// creating a string from that array might be more efficient than creating a string from the copied bytes. // creating a string from that array might be more efficient than creating a string from the copied bytes.
// Slow path: Build a byte array first then copy it. // Slow path: Build a byte array first then copy it.
return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length); return WritingPrimitives.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length);
} }
[SecuritySafeCritical] [SecuritySafeCritical]

Loading…
Cancel
Save