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
b4b0e304
Commit
b4b0e304
authored
Feb 24, 2017
by
Feng Xiao
Committed by
GitHub
Feb 24, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2355 from xfxyjwf/fixjson
Speed up JSON parsing.
parents
8387b88c
bd158fc2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
14 deletions
+20
-14
json_util.cc
src/google/protobuf/util/json_util.cc
+16
-13
json_util.h
src/google/protobuf/util/json_util.h
+4
-1
No files found.
src/google/protobuf/util/json_util.cc
View file @
b4b0e304
...
...
@@ -49,22 +49,25 @@ namespace protobuf {
namespace
util
{
namespace
internal
{
ZeroCopyStreamByteSink
::~
ZeroCopyStreamByteSink
()
{
stream_
->
BackUp
(
buffer_size_
);
}
void
ZeroCopyStreamByteSink
::
Append
(
const
char
*
bytes
,
size_t
len
)
{
while
(
len
>
0
)
{
void
*
buffer
;
int
length
;
if
(
!
stream_
->
Next
(
&
buffer
,
&
length
))
{
// There isn't a way for ByteSink to report errors.
while
(
true
)
{
if
(
len
<=
buffer_size_
)
{
memcpy
(
buffer_
,
bytes
,
len
)
;
buffer_
=
static_cast
<
char
*>
(
buffer_
)
+
len
;
buffer_size_
-=
len
;
return
;
}
if
(
len
<
length
)
{
memcpy
(
buffer
,
bytes
,
len
);
stream_
->
BackUp
(
length
-
len
);
break
;
}
else
{
memcpy
(
buffer
,
bytes
,
length
);
bytes
+=
length
;
len
-=
length
;
memcpy
(
buffer_
,
bytes
,
buffer_size_
);
bytes
+=
buffer_size_
;
len
-=
buffer_size_
;
if
(
!
stream_
->
Next
(
&
buffer_
,
&
buffer_size_
))
{
// There isn't a way for ByteSink to report errors.
buffer_size_
=
0
;
return
;
}
}
}
...
...
src/google/protobuf/util/json_util.h
View file @
b4b0e304
...
...
@@ -176,12 +176,15 @@ namespace internal {
class
LIBPROTOBUF_EXPORT
ZeroCopyStreamByteSink
:
public
strings
::
ByteSink
{
public
:
explicit
ZeroCopyStreamByteSink
(
io
::
ZeroCopyOutputStream
*
stream
)
:
stream_
(
stream
)
{}
:
stream_
(
stream
),
buffer_size_
(
0
)
{}
~
ZeroCopyStreamByteSink
();
virtual
void
Append
(
const
char
*
bytes
,
size_t
len
);
private
:
io
::
ZeroCopyOutputStream
*
stream_
;
void
*
buffer_
;
int
buffer_size_
;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
(
ZeroCopyStreamByteSink
);
};
...
...
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