Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
7ea52397
Commit
7ea52397
authored
Jul 16, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #610 from jskeet/fix-enumerator
Remove the struct-based iterator for RepeatedField.
parents
3bf74a91
78b452b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
63 deletions
+6
-63
RepeatedFieldTest.cs
...src/ProtocolBuffers.Test/Collections/RepeatedFieldTest.cs
+0
-6
RepeatedField.cs
csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
+6
-57
No files found.
csharp/src/ProtocolBuffers.Test/Collections/RepeatedFieldTest.cs
View file @
7ea52397
...
...
@@ -241,18 +241,12 @@ namespace Google.Protobuf.Collections
var
list
=
new
RepeatedField
<
string
>
{
"first"
,
"second"
};
using
(
var
enumerator
=
list
.
GetEnumerator
())
{
Assert
.
Throws
<
InvalidOperationException
>(()
=>
enumerator
.
Current
.
GetHashCode
());
Assert
.
IsTrue
(
enumerator
.
MoveNext
());
Assert
.
AreEqual
(
"first"
,
enumerator
.
Current
);
Assert
.
IsTrue
(
enumerator
.
MoveNext
());
Assert
.
AreEqual
(
"second"
,
enumerator
.
Current
);
Assert
.
IsFalse
(
enumerator
.
MoveNext
());
Assert
.
Throws
<
InvalidOperationException
>(()
=>
enumerator
.
Current
.
GetHashCode
());
Assert
.
IsFalse
(
enumerator
.
MoveNext
());
enumerator
.
Reset
();
Assert
.
Throws
<
InvalidOperationException
>(()
=>
enumerator
.
Current
.
GetHashCode
());
Assert
.
IsTrue
(
enumerator
.
MoveNext
());
Assert
.
AreEqual
(
"first"
,
enumerator
.
Current
);
}
}
...
...
csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
View file @
7ea52397
...
...
@@ -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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment