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
1b71db11
Commit
1b71db11
authored
Jun 12, 2015
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimization of CalculateSize: avoid foreach over empty lists.
parent
9b66768e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
12 deletions
+10
-12
csharp_repeated_enum_field.cc
...le/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
+1
-5
csharp_repeated_message_field.cc
...protobuf/compiler/csharp/csharp_repeated_message_field.cc
+4
-2
csharp_repeated_primitive_field.cc
...otobuf/compiler/csharp/csharp_repeated_primitive_field.cc
+5
-5
No files found.
src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
View file @
1b71db11
...
...
@@ -89,13 +89,11 @@ void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer)
void
RepeatedEnumFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): Move all this code into CodedOutputStream? It's a lot to repeat everywhere...
printer
->
Print
(
"{
\n
"
);
printer
->
Indent
();
printer
->
Print
(
variables_
,
"int dataSize = 0;
\n
"
"if ($name$_.Count > 0) {
\n
"
);
printer
->
Indent
();
printer
->
Print
(
"int dataSize = 0;
\n
"
);
printer
->
Print
(
variables_
,
"foreach ($type_name$ element in $name$_) {
\n
"
...
...
@@ -115,8 +113,6 @@ void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer
}
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
printer
->
Outdent
();
printer
->
Print
(
"}
\n
"
);
}
void
RepeatedEnumFieldGenerator
::
WriteHash
(
io
::
Printer
*
printer
)
{
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
View file @
1b71db11
...
...
@@ -90,8 +90,10 @@ void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* prin
// TODO(jonskeet): Put this into CodedOutputStream.
printer
->
Print
(
variables_
,
"foreach ($type_name$ element in $name$_) {
\n
"
" size += pb::CodedOutputStream.ComputeMessageSize($number$, element);
\n
"
"if ($name$_.Count > 0) {
\n
"
" foreach ($type_name$ element in $name$_) {
\n
"
" size += pb::CodedOutputStream.ComputeMessageSize($number$, element);
\n
"
" }
\n
"
"}
\n
"
);
}
...
...
src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
View file @
1b71db11
...
...
@@ -93,7 +93,9 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode(
void
RepeatedPrimitiveFieldGenerator
::
GenerateSerializedSizeCode
(
io
::
Printer
*
printer
)
{
// TODO(jonskeet): Do this in the runtime if possible. It's a pain, but it must be feasible...
printer
->
Print
(
"{
\n
"
);
printer
->
Print
(
"if ($name$_.Count > 0) {
\n
"
,
"name"
,
name
());
printer
->
Indent
();
printer
->
Print
(
"int dataSize = 0;
\n
"
);
int
fixedSize
=
GetFixedSize
(
descriptor_
->
type
());
...
...
@@ -112,10 +114,8 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializedSizeCode(
int
tagSize
=
internal
::
WireFormat
::
TagSize
(
descriptor_
->
number
(),
descriptor_
->
type
());
if
(
descriptor_
->
is_packed
())
{
printer
->
Print
(
"if ($name$_.Count != 0) {
\n
"
" size += $tag_size$ + pb::CodedOutputStream.ComputeInt32SizeNoTag(dataSize);
\n
"
"}
\n
"
,
"name"
,
name
(),
"tag_size"
,
SimpleItoa
(
tagSize
));
"size += $tag_size$ + pb::CodedOutputStream.ComputeInt32SizeNoTag(dataSize);
\n
"
,
"tag_size"
,
SimpleItoa
(
tagSize
));
}
else
{
printer
->
Print
(
"size += $tag_size$ * $name$_.Count;
\n
"
,
...
...
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