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
f85d70f9
Commit
f85d70f9
authored
Nov 02, 2009
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize Java serialization of small messages to streams. Patch from Evan Jones.
parent
573989f7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
2 deletions
+23
-2
CONTRIBUTORS.txt
CONTRIBUTORS.txt
+2
-0
AbstractMessageLite.java
...rc/main/java/com/google/protobuf/AbstractMessageLite.java
+9
-2
CodedOutputStream.java
.../src/main/java/com/google/protobuf/CodedOutputStream.java
+12
-0
No files found.
CONTRIBUTORS.txt
View file @
f85d70f9
...
...
@@ -76,3 +76,5 @@ Patch contributors:
* HPUX support.
Oliver Jowett <oliver.jowett@gmail.com>
* Detect whether zlib is new enough in configure script.
Evan Jones <evanj@mit.edu>
* Optimize Java serialization code when writing a small message to a stream.
java/src/main/java/com/google/protobuf/AbstractMessageLite.java
View file @
f85d70f9
...
...
@@ -72,13 +72,20 @@ public abstract class AbstractMessageLite implements MessageLite {
}
public
void
writeTo
(
final
OutputStream
output
)
throws
IOException
{
final
CodedOutputStream
codedOutput
=
CodedOutputStream
.
newInstance
(
output
);
final
int
bufferSize
=
CodedOutputStream
.
computePreferredBufferSize
(
getSerializedSize
());
final
CodedOutputStream
codedOutput
=
CodedOutputStream
.
newInstance
(
output
,
bufferSize
);
writeTo
(
codedOutput
);
codedOutput
.
flush
();
}
public
void
writeDelimitedTo
(
final
OutputStream
output
)
throws
IOException
{
final
CodedOutputStream
codedOutput
=
CodedOutputStream
.
newInstance
(
output
);
final
int
serialized
=
getSerializedSize
();
final
int
bufferSize
=
CodedOutputStream
.
computePreferredBufferSize
(
CodedOutputStream
.
computeRawVarint32Size
(
serialized
)
+
serialized
);
final
CodedOutputStream
codedOutput
=
CodedOutputStream
.
newInstance
(
output
,
bufferSize
);
codedOutput
.
writeRawVarint32
(
getSerializedSize
());
writeTo
(
codedOutput
);
codedOutput
.
flush
();
...
...
java/src/main/java/com/google/protobuf/CodedOutputStream.java
View file @
f85d70f9
...
...
@@ -60,6 +60,18 @@ public final class CodedOutputStream {
*/
public
static
final
int
DEFAULT_BUFFER_SIZE
=
4096
;
/**
* Returns the buffer size to efficiently write dataLength bytes to this
* CodedOutputStream. Used by AbstractMessageLite.
*
* @return the buffer size to efficiently write dataLength bytes to this
* CodedOutputStream.
*/
static
int
computePreferredBufferSize
(
int
dataLength
)
{
if
(
dataLength
>
DEFAULT_BUFFER_SIZE
)
return
DEFAULT_BUFFER_SIZE
;
return
dataLength
;
}
private
CodedOutputStream
(
final
byte
[]
buffer
,
final
int
offset
,
final
int
length
)
{
output
=
null
;
...
...
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