Commit 92b0aaa0 authored by Jon Skeet's avatar Jon Skeet

Use a nullable int for the memoizedSize, just because it's neater.

parent 9deef9ba
...@@ -26,12 +26,11 @@ namespace Google.ProtocolBuffers { ...@@ -26,12 +26,11 @@ namespace Google.ProtocolBuffers {
public abstract class AbstractMessage<TMessage, TBuilder> : IMessage<TMessage, TBuilder> public abstract class AbstractMessage<TMessage, TBuilder> : IMessage<TMessage, TBuilder>
where TMessage : AbstractMessage<TMessage, TBuilder> where TMessage : AbstractMessage<TMessage, TBuilder>
where TBuilder : AbstractBuilder<TMessage, TBuilder> { where TBuilder : AbstractBuilder<TMessage, TBuilder> {
// TODO(jonskeet): Cleaner to use a Nullable<int>?
/// <summary> /// <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. /// if we haven't computed it yet.
/// </summary> /// </summary>
private int memoizedSize = -1; private int? memoizedSize = null;
#region Unimplemented members of IMessage #region Unimplemented members of IMessage
public abstract MessageDescriptor DescriptorForType { get; } public abstract MessageDescriptor DescriptorForType { get; }
...@@ -113,12 +112,11 @@ namespace Google.ProtocolBuffers { ...@@ -113,12 +112,11 @@ namespace Google.ProtocolBuffers {
public virtual int SerializedSize { public virtual int SerializedSize {
get { get {
int size = memoizedSize; if (memoizedSize != null) {
if (size != -1) { return memoizedSize.Value;
return size;
} }
size = 0; int size = 0;
foreach (KeyValuePair<FieldDescriptor, object> entry in AllFields) { foreach (KeyValuePair<FieldDescriptor, object> entry in AllFields) {
FieldDescriptor field = entry.Key; FieldDescriptor field = entry.Key;
if (field.IsRepeated) { if (field.IsRepeated) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment