simplified code a bit based on @gregmarr's suggestions

This commit is contained in:
Alex Astashyn 2016-12-06 22:20:48 -05:00
parent d2e9ce270a
commit d169598c6c
2 changed files with 64 additions and 74 deletions

View file

@ -9177,8 +9177,6 @@ basic_json_parser_66:
std::array<char, 64> buf; std::array<char, 64> buf;
const size_t len = static_cast<size_t>(m_end - m_start); const size_t len = static_cast<size_t>(m_end - m_start);
const char* const data = [this, &tempstr, &buf, len]() -> const char*
{
// Since dealing with strtod family of functions, // Since dealing with strtod family of functions,
// we're getting the decimal point char from the // we're getting the decimal point char from the
// C locale facilities instead of C++'s numpunct // C locale facilities instead of C++'s numpunct
@ -9188,19 +9186,15 @@ basic_json_parser_66:
const char decimal_point_char = !loc->decimal_point ? '.' const char decimal_point_char = !loc->decimal_point ? '.'
: loc->decimal_point[0]; : loc->decimal_point[0];
if (decimal_point_char == '.') const char *data = m_start;
{
return m_start; // don't need to convert
}
if (decimal_point_char != '.')
{
const size_t ds_pos = static_cast<size_t>( const size_t ds_pos = static_cast<size_t>(
std::find(m_start, m_end, '.') - m_start ); std::find(m_start, m_end, '.') - m_start );
if (ds_pos == len) if (ds_pos != len)
{ {
return m_start; // no decimal separator
}
// copy the data into the local buffer or // copy the data into the local buffer or
// tempstr, if buffer is too small; // tempstr, if buffer is too small;
// replace decimal separator, and update // replace decimal separator, and update
@ -9210,15 +9204,16 @@ basic_json_parser_66:
std::copy(m_start, m_end, buf.data()); std::copy(m_start, m_end, buf.data());
buf[len] = 0; buf[len] = 0;
buf[ds_pos] = decimal_point_char; buf[ds_pos] = decimal_point_char;
return buf.data(); data = buf.data();
} }
else else
{ {
tempstr.assign(m_start, m_end); tempstr.assign(m_start, m_end);
tempstr[ds_pos] = decimal_point_char; tempstr[ds_pos] = decimal_point_char;
return tempstr.c_str(); data = tempstr.c_str();
}
}
} }
}();
char* endptr = nullptr; char* endptr = nullptr;
value = 0; value = 0;

View file

@ -8326,8 +8326,6 @@ class basic_json
std::array<char, 64> buf; std::array<char, 64> buf;
const size_t len = static_cast<size_t>(m_end - m_start); const size_t len = static_cast<size_t>(m_end - m_start);
const char* const data = [this, &tempstr, &buf, len]() -> const char*
{
// Since dealing with strtod family of functions, // Since dealing with strtod family of functions,
// we're getting the decimal point char from the // we're getting the decimal point char from the
// C locale facilities instead of C++'s numpunct // C locale facilities instead of C++'s numpunct
@ -8337,19 +8335,15 @@ class basic_json
const char decimal_point_char = !loc->decimal_point ? '.' const char decimal_point_char = !loc->decimal_point ? '.'
: loc->decimal_point[0]; : loc->decimal_point[0];
if (decimal_point_char == '.') const char *data = m_start;
{
return m_start; // don't need to convert
}
if (decimal_point_char != '.')
{
const size_t ds_pos = static_cast<size_t>( const size_t ds_pos = static_cast<size_t>(
std::find(m_start, m_end, '.') - m_start ); std::find(m_start, m_end, '.') - m_start );
if (ds_pos == len) if (ds_pos != len)
{ {
return m_start; // no decimal separator
}
// copy the data into the local buffer or // copy the data into the local buffer or
// tempstr, if buffer is too small; // tempstr, if buffer is too small;
// replace decimal separator, and update // replace decimal separator, and update
@ -8359,15 +8353,16 @@ class basic_json
std::copy(m_start, m_end, buf.data()); std::copy(m_start, m_end, buf.data());
buf[len] = 0; buf[len] = 0;
buf[ds_pos] = decimal_point_char; buf[ds_pos] = decimal_point_char;
return buf.data(); data = buf.data();
} }
else else
{ {
tempstr.assign(m_start, m_end); tempstr.assign(m_start, m_end);
tempstr[ds_pos] = decimal_point_char; tempstr[ds_pos] = decimal_point_char;
return tempstr.c_str(); data = tempstr.c_str();
}
}
} }
}();
char* endptr = nullptr; char* endptr = nullptr;
value = 0; value = 0;