Bläddra i källkod

cleanup coded output stream

Jan Tattermusch 5 år sedan
förälder
incheckning
7bfaaba534

+ 1 - 1
csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs

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

+ 0 - 32
csharp/src/Google.Protobuf/CodedOutputStream.cs

@@ -59,9 +59,6 @@ namespace Google.Protobuf
     [SecuritySafeCritical]
     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>
         /// The buffer size used by CreateInstance(Stream).
         /// </summary>
@@ -551,35 +548,6 @@ namespace Google.Protobuf
 
         #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()
         //{
         //    if (output == null)

+ 3 - 3
csharp/src/Google.Protobuf/ParsingPrimitives.cs

@@ -629,7 +629,7 @@ namespace Google.Protobuf
                 {
                     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
 
-            var decoder = CodedOutputStream.Utf8Encoding.GetDecoder();
+            var decoder = WritingPrimitives.Utf8Encoding.GetDecoder();
 
             // 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)
@@ -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.
 
             // 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]