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
c3115431
Commit
c3115431
authored
8 years ago
by
Feng Xiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid redundant type casts for oneof bytes fields.
parent
fa178802
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
+22
-4
java_primitive_field.cc
src/google/protobuf/compiler/java/java_primitive_field.cc
+22
-4
No files found.
src/google/protobuf/compiler/java/java_primitive_field.cc
View file @
c3115431
...
...
@@ -523,8 +523,17 @@ void ImmutablePrimitiveOneofFieldGenerator::
GenerateSerializationCode
(
io
::
Printer
*
printer
)
const
{
printer
->
Print
(
variables_
,
"if ($has_oneof_case_message$) {
\n
"
" output.write$capitalized_type$(
\n
"
" $number$, ($type$)(($boxed_type$) $oneof_name$_));
\n
"
" output.write$capitalized_type$(
\n
"
);
// $type$ and $boxed_type$ is the same for bytes fields so we don't need to
// do redundant casts.
if
(
GetJavaType
(
descriptor_
)
==
JAVATYPE_BYTES
)
{
printer
->
Print
(
variables_
,
" $number$, ($type$) $oneof_name$_);
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
" $number$, ($type$)(($boxed_type$) $oneof_name$_));
\n
"
);
}
printer
->
Print
(
"}
\n
"
);
}
...
...
@@ -533,8 +542,17 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
printer
->
Print
(
variables_
,
"if ($has_oneof_case_message$) {
\n
"
" size += com.google.protobuf.CodedOutputStream
\n
"
" .compute$capitalized_type$Size(
\n
"
" $number$, ($type$)(($boxed_type$) $oneof_name$_));
\n
"
" .compute$capitalized_type$Size(
\n
"
);
// $type$ and $boxed_type$ is the same for bytes fields so we don't need to
// do redundant casts.
if
(
GetJavaType
(
descriptor_
)
==
JAVATYPE_BYTES
)
{
printer
->
Print
(
variables_
,
" $number$, ($type$) $oneof_name$_);
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
" $number$, ($type$)(($boxed_type$) $oneof_name$_));
\n
"
);
}
printer
->
Print
(
"}
\n
"
);
}
...
...
This diff is collapsed.
Click to expand it.
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