added performance fixes (#365)

This commit is contained in:
Niels 2016-11-22 07:26:11 +01:00
parent 869f4c68d4
commit f620d74919
2 changed files with 44 additions and 30 deletions

View file

@ -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:
// 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:
// 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:
} }
} }
} }
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:
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

View file

@ -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
// 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
// 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
} }
} }
} }
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
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