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
f4cfd2de
Commit
f4cfd2de
authored
May 05, 2019
by
Sydney Acksman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dead HasValue code for ExtensionValue and add null-checks to ExtensionSet.Set
parent
8dc69ede
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
26 deletions
+11
-26
ExtensionSet.cs
csharp/src/Google.Protobuf/ExtensionSet.cs
+2
-0
ExtensionValue.cs
csharp/src/Google.Protobuf/ExtensionValue.cs
+9
-20
CustomOptions.cs
csharp/src/Google.Protobuf/Reflection/CustomOptions.cs
+0
-6
No files found.
csharp/src/Google.Protobuf/ExtensionSet.cs
View file @
f4cfd2de
...
...
@@ -115,6 +115,8 @@ namespace Google.Protobuf
/// </summary>
public
static
void
Set
<
TTarget
,
TValue
>(
ref
ExtensionSet
<
TTarget
>
set
,
Extension
<
TTarget
,
TValue
>
extension
,
TValue
value
)
where
TTarget
:
IExtendableMessage
<
TTarget
>
{
ProtoPreconditions
.
CheckNotNullUnconstrained
(
value
,
nameof
(
value
));
IExtensionValue
extensionValue
;
if
(
set
==
null
)
{
...
...
csharp/src/Google.Protobuf/ExtensionValue.cs
View file @
f4cfd2de
...
...
@@ -47,7 +47,6 @@ namespace Google.Protobuf
internal
sealed
class
ExtensionValue
<
T
>
:
IExtensionValue
{
private
bool
hasValue
;
private
T
field
;
private
FieldCodec
<
T
>
codec
;
...
...
@@ -59,10 +58,6 @@ namespace Google.Protobuf
public
int
CalculateSize
()
{
if
(!
hasValue
)
{
return
0
;
}
return
codec
.
CalculateSizeWithTag
(
field
);
}
...
...
@@ -70,7 +65,6 @@ namespace Google.Protobuf
{
return
new
ExtensionValue
<
T
>(
codec
)
{
hasValue
=
hasValue
,
field
=
field
is
IDeepCloneable
<
T
>
?
(
field
as
IDeepCloneable
<
T
>).
Clone
()
:
field
};
}
...
...
@@ -82,7 +76,6 @@ namespace Google.Protobuf
return
other
is
ExtensionValue
<
T
>
&&
codec
.
Equals
((
other
as
ExtensionValue
<
T
>).
codec
)
&&
hasValue
.
Equals
((
other
as
ExtensionValue
<
T
>).
hasValue
)
&&
Equals
(
field
,
(
other
as
ExtensionValue
<
T
>).
field
);
// we check for equality in the codec since we could have equal field values however the values could be written in different ways
}
...
...
@@ -92,7 +85,6 @@ namespace Google.Protobuf
unchecked
{
int
hash
=
17
;
hash
=
hash
*
31
+
hasValue
.
GetHashCode
();
hash
=
hash
*
31
+
field
.
GetHashCode
();
hash
=
hash
*
31
+
codec
.
GetHashCode
();
return
hash
;
...
...
@@ -101,7 +93,6 @@ namespace Google.Protobuf
public
void
MergeFrom
(
CodedInputStream
input
)
{
hasValue
=
true
;
codec
.
ValueMerger
(
input
,
ref
field
);
}
...
...
@@ -110,16 +101,11 @@ namespace Google.Protobuf
if
(
value
is
ExtensionValue
<
T
>)
{
var
extensionValue
=
value
as
ExtensionValue
<
T
>;
if
(
extensionValue
.
hasValue
)
{
hasValue
|=
codec
.
FieldMerger
(
ref
field
,
extensionValue
.
field
);
}
codec
.
FieldMerger
(
ref
field
,
extensionValue
.
field
);
}
}
public
void
WriteTo
(
CodedOutputStream
output
)
{
if
(
hasValue
)
{
output
.
WriteTag
(
codec
.
Tag
);
codec
.
ValueWriter
(
output
,
field
);
...
...
@@ -128,21 +114,24 @@ namespace Google.Protobuf
output
.
WriteTag
(
codec
.
EndTag
);
}
}
}
public
T
GetValue
()
=>
field
;
public
void
SetValue
(
T
value
)
{
hasValue
=
true
;
field
=
value
;
}
public
bool
HasValue
=>
hasValue
;
public
bool
IsInitialized
()
{
return
HasValue
&&
field
is
IMessage
&&
(
field
as
IMessage
).
IsInitialized
();
if
(
field
is
IMessage
)
{
return
(
field
as
IMessage
).
IsInitialized
();
}
else
{
return
true
;
}
}
}
...
...
csharp/src/Google.Protobuf/Reflection/CustomOptions.cs
View file @
f4cfd2de
...
...
@@ -254,12 +254,9 @@ namespace Google.Protobuf.Reflection
if
(
extensionValue
is
ExtensionValue
<
T
>)
{
ExtensionValue
<
T
>
single
=
extensionValue
as
ExtensionValue
<
T
>;
if
(
single
.
HasValue
)
{
value
=
single
.
GetValue
();
return
true
;
}
}
else
if
(
extensionValue
is
RepeatedExtensionValue
<
T
>)
{
RepeatedExtensionValue
<
T
>
repeated
=
extensionValue
as
RepeatedExtensionValue
<
T
>;
...
...
@@ -278,14 +275,11 @@ namespace Google.Protobuf.Reflection
var
typeInfo
=
type
.
GetTypeInfo
();
var
typeArgs
=
typeInfo
.
GenericTypeArguments
;
if
(
typeArgs
.
Length
==
1
&&
typeArgs
[
0
].
GetTypeInfo
().
IsEnum
)
{
if
((
bool
)
typeInfo
.
GetDeclaredProperty
(
nameof
(
ExtensionValue
<
T
>.
HasValue
)).
GetValue
(
extensionValue
))
{
value
=
(
T
)
typeInfo
.
GetDeclaredMethod
(
nameof
(
ExtensionValue
<
T
>.
GetValue
)).
Invoke
(
extensionValue
,
EmptyParameters
);
return
true
;
}
}
}
else
if
(
type
.
GetGenericTypeDefinition
()
==
typeof
(
RepeatedExtensionValue
<>))
{
var
typeInfo
=
type
.
GetTypeInfo
();
...
...
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