diff options
author | Jon Skeet <jonskeet@google.com> | 2015-06-30 13:16:20 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-06-30 13:20:31 +0100 |
commit | f34d37a3d4d64621bc87aa0a65a05cab64062399 (patch) | |
tree | 416cceb9b343b21004b030deea069553644928d3 /csharp/src/ProtocolBuffers/Collections/RepeatedField.cs | |
parent | b9d1d3891f4e68886398bbf0caf40229275a448a (diff) | |
download | protobuf-f34d37a3d4d64621bc87aa0a65a05cab64062399.tar.gz protobuf-f34d37a3d4d64621bc87aa0a65a05cab64062399.tar.bz2 protobuf-f34d37a3d4d64621bc87aa0a65a05cab64062399.zip |
Tidying up and extra tests.
This is mostly just making things internal instead of public, removing and reordering a bunch of code in CodedInputStream/CodedOutputStream, and generally tidying up.
Diffstat (limited to 'csharp/src/ProtocolBuffers/Collections/RepeatedField.cs')
-rw-r--r-- | csharp/src/ProtocolBuffers/Collections/RepeatedField.cs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs index 588f66a4..0d82e3bc 100644 --- a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs +++ b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs @@ -51,12 +51,14 @@ namespace Google.Protobuf.Collections public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec) { + // TODO: Inline some of the Add code, so we can avoid checking the size on every + // iteration and the mutability. uint tag = input.LastTag; var reader = codec.ValueReader; // Value types can be packed or not. if (typeof(T).IsValueType && WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited) { - int length = (int)(input.ReadRawVarint32() & int.MaxValue); + int length = input.ReadLength(); if (length > 0) { int oldLimit = input.PushLimit(length); @@ -125,7 +127,6 @@ namespace Google.Protobuf.Collections public void WriteTo(CodedOutputStream output, FieldCodec<T> codec) { - // TODO: Assert that T is a value type, and that codec.Tag is packed? if (count == 0) { return; @@ -172,9 +173,9 @@ namespace Google.Protobuf.Collections private void EnsureSize(int size) { - size = Math.Max(size, MinArraySize); if (array.Length < size) { + size = Math.Max(size, MinArraySize); int newSize = Math.Max(array.Length * 2, size); var tmp = new T[newSize]; Array.Copy(array, 0, tmp, 0, array.Length); |