aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/CodedInputStream.cs
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2015-06-12 13:07:51 +0100
committerJon Skeet <skeet@pobox.com>2015-06-12 13:07:51 +0100
commit7532f0256f58e0d11711da4e159534bccbf266f0 (patch)
tree246de5832a971caff8dcf85db1f971aed2c48f3c /csharp/src/ProtocolBuffers/CodedInputStream.cs
parent5a33827eec75b980fb152c531e4c6b75ce5af015 (diff)
downloadprotobuf-7532f0256f58e0d11711da4e159534bccbf266f0.tar.gz
protobuf-7532f0256f58e0d11711da4e159534bccbf266f0.tar.bz2
protobuf-7532f0256f58e0d11711da4e159534bccbf266f0.zip
Reimplement RepeatedField<T> using an array as the backing store.
This is effectively reimplementing List<T>, but with a few advantages: - We know that an empty repeated field is common, so don't allocate an array until we need to - With direct access to the array, we can easily convert enum values to int without boxing - We can relax the restrictions over what happens if the repeated field is modified while iterating, avoiding so much checking This is somewhat risky, in that reimplementing a building block like this is *always* risky, but hey... (The performance benefits are significant...)
Diffstat (limited to 'csharp/src/ProtocolBuffers/CodedInputStream.cs')
-rw-r--r--csharp/src/ProtocolBuffers/CodedInputStream.cs7
1 files changed, 4 insertions, 3 deletions
diff --git a/csharp/src/ProtocolBuffers/CodedInputStream.cs b/csharp/src/ProtocolBuffers/CodedInputStream.cs
index 17fcc64b..447adbb1 100644
--- a/csharp/src/ProtocolBuffers/CodedInputStream.cs
+++ b/csharp/src/ProtocolBuffers/CodedInputStream.cs
@@ -38,6 +38,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
+using Google.Protobuf.Collections;
using Google.Protobuf.Descriptors;
namespace Google.Protobuf
@@ -700,7 +701,7 @@ namespace Google.Protobuf
}
}
- public void ReadEnumArray<T>(uint fieldTag, ICollection<T> list)
+ public void ReadEnumArray<T>(uint fieldTag, RepeatedField<T> list)
where T : struct, IComparable, IFormattable
{
WireFormat.WireType wformat = WireFormat.GetTagWireType(fieldTag);
@@ -712,8 +713,8 @@ namespace Google.Protobuf
int limit = PushLimit(length);
while (!ReachedLimit)
{
- // TODO(jonskeet): Avoid this horrible boxing!
- list.Add((T)(object) ReadEnum());
+ // Ghastly hack, but it works...
+ list.AddInt32(ReadEnum());
}
PopLimit(limit);
}