diff options
author | Jon Skeet <skeet@pobox.com> | 2008-08-15 21:12:55 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2008-08-15 21:12:55 +0100 |
commit | 92b0aaa09e4f6fa037189290acc3d59481cd4108 (patch) | |
tree | deec7cf7db7e7efcf50d0d3ccad5bf9fc6994e65 | |
parent | 9deef9baec08d5ccc5a1ea78bc078eb42d6d03b7 (diff) | |
download | protobuf-92b0aaa09e4f6fa037189290acc3d59481cd4108.tar.gz protobuf-92b0aaa09e4f6fa037189290acc3d59481cd4108.tar.bz2 protobuf-92b0aaa09e4f6fa037189290acc3d59481cd4108.zip |
Use a nullable int for the memoizedSize, just because it's neater.
-rw-r--r-- | csharp/ProtocolBuffers/AbstractMessage.cs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/csharp/ProtocolBuffers/AbstractMessage.cs b/csharp/ProtocolBuffers/AbstractMessage.cs index 87172932..d8b9e9e6 100644 --- a/csharp/ProtocolBuffers/AbstractMessage.cs +++ b/csharp/ProtocolBuffers/AbstractMessage.cs @@ -26,12 +26,11 @@ namespace Google.ProtocolBuffers { public abstract class AbstractMessage<TMessage, TBuilder> : IMessage<TMessage, TBuilder> where TMessage : AbstractMessage<TMessage, TBuilder> where TBuilder : AbstractBuilder<TMessage, TBuilder> { - // TODO(jonskeet): Cleaner to use a Nullable<int>? /// <summary> - /// The serialized size if it's already been computed, or -1 + /// The serialized size if it's already been computed, or null /// if we haven't computed it yet. /// </summary> - private int memoizedSize = -1; + private int? memoizedSize = null; #region Unimplemented members of IMessage public abstract MessageDescriptor DescriptorForType { get; } @@ -113,12 +112,11 @@ namespace Google.ProtocolBuffers { public virtual int SerializedSize { get { - int size = memoizedSize; - if (size != -1) { - return size; + if (memoizedSize != null) { + return memoizedSize.Value; } - size = 0; + int size = 0; foreach (KeyValuePair<FieldDescriptor, object> entry in AllFields) { FieldDescriptor field = entry.Key; if (field.IsRepeated) { |