Skip to content

Commit

Permalink
Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Jan 26, 2021
1 parent 6b2595e commit 356e831
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions csharp/src/Google.Protobuf/WritingPrimitives.cs
Expand Up @@ -164,7 +164,6 @@ public static void WriteBool(ref Span<byte> buffer, ref WriterInternalState stat
/// </summary>
public static void WriteString(ref Span<byte> buffer, ref WriterInternalState state, string value)
{
#if !NETSTANDARD1_1
const int MaxBytesPerChar = 3;
const int MaxSmallStringLength = 128 / MaxBytesPerChar;

Expand All @@ -174,10 +173,11 @@ public static void WriteString(ref Span<byte> buffer, ref WriterInternalState st
// This saves calling GetByteCount on the string. We get the string length from GetBytes.
if (value.Length <= MaxSmallStringLength && buffer.Length - state.position - 1 >= value.Length * MaxBytesPerChar)
{
// Get the original position, then increment it on state by 1, then write string to buffer.
// Method will return byte length, which is then set to the original position.
buffer[state.position++] = (byte)WriteStringToBuffer(buffer, ref state, value);
return;
}
#endif

int length = Utf8Encoding.GetByteCount(value);
WriteLength(ref buffer, ref state, length);
Expand Down

0 comments on commit 356e831

Please sign in to comment.