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
d7dda2fe
Commit
d7dda2fe
authored
Jun 19, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use an empty array instead of a null reference for an empty repeated field.
parent
a0f95693
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
22 deletions
+10
-22
RepeatedField.cs
csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
+10
-22
No files found.
csharp/src/ProtocolBuffers/Collections/RepeatedField.cs
View file @
d7dda2fe
...
...
@@ -6,25 +6,21 @@ namespace Google.Protobuf.Collections
{
public
sealed
class
RepeatedField
<
T
>
:
IList
<
T
>,
IEquatable
<
RepeatedField
<
T
>>
{
private
static
readonly
T
[]
EmptyArray
=
new
T
[
0
];
private
const
int
MinArraySize
=
8
;
private
T
[]
array
=
null
;
private
T
[]
array
=
EmptyArray
;
private
int
count
=
0
;
private
void
EnsureSize
(
int
size
)
{
if
(
array
==
null
)
{
array
=
new
T
[
Math
.
Max
(
size
,
MinArraySize
)];
}
else
size
=
Math
.
Max
(
size
,
MinArraySize
);
if
(
array
.
Length
<
size
)
{
if
(
array
.
Length
<
size
)
{
int
newSize
=
Math
.
Max
(
array
.
Length
*
2
,
size
);
var
tmp
=
new
T
[
newSize
];
Array
.
Copy
(
array
,
0
,
tmp
,
0
,
array
.
Length
);
array
=
tmp
;
}
int
newSize
=
Math
.
Max
(
array
.
Length
*
2
,
size
);
var
tmp
=
new
T
[
newSize
];
Array
.
Copy
(
array
,
0
,
tmp
,
0
,
array
.
Length
);
array
=
tmp
;
}
}
...
...
@@ -51,7 +47,7 @@ namespace Google.Protobuf.Collections
public
void
Clear
()
{
array
=
null
;
array
=
EmptyArray
;
count
=
0
;
}
...
...
@@ -62,10 +58,6 @@ namespace Google.Protobuf.Collections
public
void
CopyTo
(
T
[]
array
,
int
arrayIndex
)
{
if
(
this
.
array
==
null
)
{
return
;
}
Array
.
Copy
(
this
.
array
,
0
,
array
,
arrayIndex
,
count
);
}
...
...
@@ -183,10 +175,6 @@ namespace Google.Protobuf.Collections
{
throw
new
ArgumentNullException
(
"item"
);
}
if
(
array
==
null
)
{
return
-
1
;
}
// TODO(jonskeet): Does this box for enums?
EqualityComparer
<
T
>
comparer
=
EqualityComparer
<
T
>.
Default
;
for
(
int
i
=
0
;
i
<
count
;
i
++)
...
...
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