aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/ProtocolBuffers/Collections
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-07-16 09:26:10 +0100
committerJon Skeet <jonskeet@google.com>2015-07-16 09:26:10 +0100
commit78b452b7acf985747d3d2813dedea3d267b08bae (patch)
treef1f80ed866d477d9b22d13898ec78dc8a21d5269 /csharp/src/ProtocolBuffers/Collections
parent3bf74a91bb936c71bfbe61db5c87d10eaac1bc41 (diff)
downloadprotobuf-78b452b7acf985747d3d2813dedea3d267b08bae.tar.gz
protobuf-78b452b7acf985747d3d2813dedea3d267b08bae.tar.bz2
protobuf-78b452b7acf985747d3d2813dedea3d267b08bae.zip
Remove the struct-based iterator for RepeatedField.
We don't use it in the runtime or generated code anywhere now, so the extra small performance boost isn't as critical, and it has some undesirable consequences. The tests have needed to change as iterator block enumerators don't throw when we might expect them to.
Diffstat (limited to 'csharp/src/ProtocolBuffers/Collections')
-rw-r--r--csharp/src/ProtocolBuffers/Collections/RepeatedField.cs63
1 files changed, 6 insertions, 57 deletions
diff --git a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
index a09c7954..8375ae0b 100644
--- a/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
+++ b/csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
@@ -288,14 +288,12 @@ namespace Google.Protobuf.Collections
}
}
- public RepeatedField<T>.Enumerator GetEnumerator()
+ public IEnumerator<T> GetEnumerator()
{
- return new Enumerator(this);
- }
-
- IEnumerator<T> IEnumerable<T>.GetEnumerator()
- {
- return GetEnumerator();
+ for (int i = 0; i < count; i++)
+ {
+ yield return array[i];
+ }
}
public override bool Equals(object obj)
@@ -467,55 +465,6 @@ namespace Google.Protobuf.Collections
}
Remove((T)value);
}
- #endregion
-
- public struct Enumerator : IEnumerator<T>
- {
- private int index;
- private readonly RepeatedField<T> field;
-
- public Enumerator(RepeatedField<T> field)
- {
- this.field = field;
- this.index = -1;
- }
-
- public bool MoveNext()
- {
- if (index + 1 >= field.Count)
- {
- index = field.Count;
- return false;
- }
- index++;
- return true;
- }
-
- public void Reset()
- {
- index = -1;
- }
-
- public T Current
- {
- get
- {
- if (index == -1 || index >= field.count)
- {
- throw new InvalidOperationException();
- }
- return field.array[index];
- }
- }
-
- object IEnumerator.Current
- {
- get { return Current; }
- }
-
- public void Dispose()
- {
- }
- }
+ #endregion
}
}