Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
f620d749
Commit
f620d749
authored
Nov 22, 2016
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
⚡
added performance fixes (#365)
parent
869f4c68
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
30 deletions
+44
-30
json.hpp
src/json.hpp
+22
-15
json.hpp.re2c
src/json.hpp.re2c
+22
-15
No files found.
src/json.hpp
View file @
f620d749
...
@@ -8734,10 +8734,10 @@ basic_json_parser_66:
...
@@ -8734,10 +8734,10 @@ basic_json_parser_66:
{
{
// copy unprocessed characters to line buffer
// copy unprocessed characters to line buffer
m_line_buffer
.
clear
();
m_line_buffer
.
clear
();
for
(
m_cursor
=
m_start
;
m_cursor
!=
m_limit
;
++
m_cursor
)
m_line_buffer
.
append
(
{
reinterpret_cast
<
const
typename
string_t
::
value_type
*>
(
m_start
),
m_line_buffer
.
append
(
1
,
static_cast
<
const
char
>
(
*
m_cursor
));
static_cast
<
size_t
>
(
m_limit
-
m_start
));
}
m_cursor
=
m_limit
;
}
}
// append n characters to make sure that there is sufficient
// append n characters to make sure that there is sufficient
...
@@ -8750,10 +8750,12 @@ basic_json_parser_66:
...
@@ -8750,10 +8750,12 @@ basic_json_parser_66:
// delete processed characters from line buffer
// delete processed characters from line buffer
m_line_buffer
.
erase
(
0
,
static_cast
<
size_t
>
(
offset_start
));
m_line_buffer
.
erase
(
0
,
static_cast
<
size_t
>
(
offset_start
));
// read next line from input stream
// read next line from input stream
std
::
string
line
;
m_line_buffer_tmp
.
clear
();
std
::
getline
(
*
m_stream
,
line
,
'\n'
);
std
::
getline
(
*
m_stream
,
m_line_buffer_tmp
,
'\n'
);
// add line with newline symbol to the line buffer
// add line with newline symbol to the line buffer
m_line_buffer
+=
line
+
"
\n
"
;
m_line_buffer
+=
m_line_buffer_tmp
;
m_line_buffer
.
push_back
(
'\n'
);
}
}
// set pointers
// set pointers
...
@@ -8840,9 +8842,18 @@ basic_json_parser_66:
...
@@ -8840,9 +8842,18 @@ basic_json_parser_66:
// iterate the result between the quotes
// iterate the result between the quotes
for
(
const
lexer_char_t
*
i
=
m_start
+
1
;
i
<
m_cursor
-
1
;
++
i
)
for
(
const
lexer_char_t
*
i
=
m_start
+
1
;
i
<
m_cursor
-
1
;
++
i
)
{
{
// process escaped characters
// number of non-escaped characters
if
(
*
i
==
'\\'
)
const
size_t
n
=
static_cast
<
size_t
>
(
std
::
find
(
i
,
m_cursor
-
1
,
'\\'
)
-
i
);
if
(
n
!=
0
)
{
{
result
.
append
(
reinterpret_cast
<
const
typename
string_t
::
value_type
*>
(
i
),
n
);
i
+=
n
-
1
;
// -1 because will ++i
}
else
{
// processing escaped character
// read next character
// read next character
++
i
;
++
i
;
...
@@ -8929,12 +8940,6 @@ basic_json_parser_66:
...
@@ -8929,12 +8940,6 @@ basic_json_parser_66:
}
}
}
}
}
}
else
{
// all other characters are just copied to the end of the
// string
result
.
append
(
1
,
static_cast
<
typename
string_t
::
value_type
>
(
*
i
));
}
}
}
return
result
;
return
result
;
...
@@ -9118,6 +9123,8 @@ basic_json_parser_66:
...
@@ -9118,6 +9123,8 @@ basic_json_parser_66:
std
::
istream
*
m_stream
=
nullptr
;
std
::
istream
*
m_stream
=
nullptr
;
/// line buffer buffer for m_stream
/// line buffer buffer for m_stream
string_t
m_line_buffer
{};
string_t
m_line_buffer
{};
/// used for filling m_line_buffer
string_t
m_line_buffer_tmp
{};
/// the buffer pointer
/// the buffer pointer
const
lexer_char_t
*
m_content
=
nullptr
;
const
lexer_char_t
*
m_content
=
nullptr
;
/// pointer to the beginning of the current symbol
/// pointer to the beginning of the current symbol
...
...
src/json.hpp.re2c
View file @
f620d749
...
@@ -7883,10 +7883,10 @@ class basic_json
...
@@ -7883,10 +7883,10 @@ class basic_json
{
{
// copy unprocessed characters to line buffer
// copy unprocessed characters to line buffer
m_line_buffer.clear();
m_line_buffer.clear();
for (m_cursor = m_start; m_cursor != m_limit; ++m_cursor)
m_line_buffer.append(
{
reinterpret_cast<const typename string_t::value_type*>(m_start),
m_line_buffer.append(1, static_cast<const char>(*m_cursor
));
static_cast<size_t>(m_limit - m_start
));
}
m_cursor = m_limit;
}
}
// append n characters to make sure that there is sufficient
// append n characters to make sure that there is sufficient
...
@@ -7899,10 +7899,12 @@ class basic_json
...
@@ -7899,10 +7899,12 @@ class basic_json
// delete processed characters from line buffer
// delete processed characters from line buffer
m_line_buffer.erase(0, static_cast<size_t>(offset_start));
m_line_buffer.erase(0, static_cast<size_t>(offset_start));
// read next line from input stream
// read next line from input stream
std::string line;
m_line_buffer_tmp.clear();
std::getline(*m_stream, line, '\n');
std::getline(*m_stream, m_line_buffer_tmp, '\n');
// add line with newline symbol to the line buffer
// add line with newline symbol to the line buffer
m_line_buffer += line + "\n";
m_line_buffer += m_line_buffer_tmp;
m_line_buffer.push_back('\n');
}
}
// set pointers
// set pointers
...
@@ -7989,9 +7991,18 @@ class basic_json
...
@@ -7989,9 +7991,18 @@ class basic_json
// iterate the result between the quotes
// iterate the result between the quotes
for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
{
{
// process escaped characters
// number of non-escaped characters
if (*i == '\\')
const size_t n = static_cast<size_t>(std::find(i, m_cursor - 1, '\\') - i);
if (n != 0)
{
result.append(reinterpret_cast<const typename string_t::value_type*>(i), n);
i += n - 1; // -1 because will ++i
}
else
{
{
// processing escaped character
// read next character
// read next character
++i;
++i;
...
@@ -8078,12 +8089,6 @@ class basic_json
...
@@ -8078,12 +8089,6 @@ class basic_json
}
}
}
}
}
}
else
{
// all other characters are just copied to the end of the
// string
result.append(1, static_cast<typename string_t::value_type>(*i));
}
}
}
return result;
return result;
...
@@ -8267,6 +8272,8 @@ class basic_json
...
@@ -8267,6 +8272,8 @@ class basic_json
std::istream* m_stream = nullptr;
std::istream* m_stream = nullptr;
/// line buffer buffer for m_stream
/// line buffer buffer for m_stream
string_t m_line_buffer {};
string_t m_line_buffer {};
/// used for filling m_line_buffer
string_t m_line_buffer_tmp {};
/// the buffer pointer
/// the buffer pointer
const lexer_char_t* m_content = nullptr;
const lexer_char_t* m_content = nullptr;
/// pointer to the beginning of the current symbol
/// pointer to the beginning of the current symbol
...
...
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