diff options
author | Jon Skeet <skeet@pobox.com> | 2009-03-05 14:23:17 +0000 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2009-03-05 14:23:17 +0000 |
commit | 7de1aef8488e48d9df35d2207ef28de0ea42a296 (patch) | |
tree | 7808804ff3a15e70932c6dab09965f4816ad1066 /src/ProtoGen/RepeatedEnumFieldGenerator.cs | |
parent | 75f4268e601fbd6a0de050b5da4aa7767c86c513 (diff) | |
download | protobuf-7de1aef8488e48d9df35d2207ef28de0ea42a296.tar.gz protobuf-7de1aef8488e48d9df35d2207ef28de0ea42a296.tar.bz2 protobuf-7de1aef8488e48d9df35d2207ef28de0ea42a296.zip |
Avoid creating UnknownFieldSets unless we really have to.
Diffstat (limited to 'src/ProtoGen/RepeatedEnumFieldGenerator.cs')
-rw-r--r-- | src/ProtoGen/RepeatedEnumFieldGenerator.cs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/ProtoGen/RepeatedEnumFieldGenerator.cs b/src/ProtoGen/RepeatedEnumFieldGenerator.cs index 1bd6c005..473970f9 100644 --- a/src/ProtoGen/RepeatedEnumFieldGenerator.cs +++ b/src/ProtoGen/RepeatedEnumFieldGenerator.cs @@ -79,11 +79,14 @@ namespace Google.ProtocolBuffers.ProtoGen { // TODO(jonskeet): Make a more efficient way of doing this writer.WriteLine("int rawValue = input.ReadEnum();"); writer.WriteLine("if (!global::System.Enum.IsDefined(typeof({0}), rawValue)) {{", TypeName); + writer.WriteLine(" if (unknownFields == null) {"); // First unknown field - create builder now + writer.WriteLine(" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);"); + writer.WriteLine(" }"); writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong) rawValue);", Number); writer.WriteLine("} else {"); writer.WriteLine(" Add{0}(({1}) rawValue);", PropertyName, TypeName); writer.WriteLine("}"); - + if (Descriptor.IsPacked) { writer.Outdent(); writer.WriteLine("}"); |