aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2015-06-11 14:19:30 +0100
committerJon Skeet <skeet@pobox.com>2015-06-11 14:19:30 +0100
commit35e4dbd51829216fd1ad85a95c01042346b63c6b (patch)
tree0841c7e6f967bc39c0fe933aa9bc63c740f138aa /csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
parent954e720837be515254360cf9fdf3d9681c1bd91c (diff)
downloadprotobuf-35e4dbd51829216fd1ad85a95c01042346b63c6b.tar.gz
protobuf-35e4dbd51829216fd1ad85a95c01042346b63c6b.tar.bz2
protobuf-35e4dbd51829216fd1ad85a95c01042346b63c6b.zip
Improve string encoding times.
Cache a reference to Encoding.UTF8 - the property access is (rather surprisingly) significant. Additionally, when we detect that the string is all ASCII (due to the computed length in bytes being the length in characters), we can perform the encoding very efficiently ourselves.
Diffstat (limited to 'csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs')
-rw-r--r--csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs4
1 files changed, 2 insertions, 2 deletions
diff --git a/csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs b/csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
index 5457f79f..58475ff7 100644
--- a/csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
+++ b/csharp/src/ProtocolBuffers/CodedOutputStream.ComputeSize.cs
@@ -135,7 +135,7 @@ namespace Google.Protobuf
/// </summary>
public static int ComputeStringSize(int fieldNumber, String value)
{
- int byteArraySize = Encoding.UTF8.GetByteCount(value);
+ int byteArraySize = UTF8.GetByteCount(value);
return ComputeTagSize(fieldNumber) +
ComputeRawVarint32Size((uint) byteArraySize) +
byteArraySize;
@@ -323,7 +323,7 @@ namespace Google.Protobuf
/// </summary>
public static int ComputeStringSizeNoTag(String value)
{
- int byteArraySize = Encoding.UTF8.GetByteCount(value);
+ int byteArraySize = UTF8.GetByteCount(value);
return ComputeRawVarint32Size((uint) byteArraySize) +
byteArraySize;
}