🔨 clean up

parent 9fc093c9
...@@ -204,7 +204,7 @@ boundaries compute_boundaries(FloatType value) ...@@ -204,7 +204,7 @@ boundaries compute_boundaries(FloatType value)
const std::uint64_t E = bits >> (kPrecision - 1); const std::uint64_t E = bits >> (kPrecision - 1);
const std::uint64_t F = bits & (kHiddenBit - 1); const std::uint64_t F = bits & (kHiddenBit - 1);
const bool is_denormal = (E == 0); const bool is_denormal = E == 0;
const diyfp v = is_denormal const diyfp v = is_denormal
? diyfp(F, kMinExp) ? diyfp(F, kMinExp)
: diyfp(F + kHiddenBit, static_cast<int>(E) - kBias); : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
...@@ -230,7 +230,7 @@ boundaries compute_boundaries(FloatType value) ...@@ -230,7 +230,7 @@ boundaries compute_boundaries(FloatType value)
// -----------------+------+------+-------------+-------------+--- (B) // -----------------+------+------+-------------+-------------+--- (B)
// v- m- v m+ v+ // v- m- v m+ v+
const bool lower_boundary_is_closer = (F == 0 and E > 1); const bool lower_boundary_is_closer = F == 0 and E > 1;
const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1); const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
const diyfp m_minus = lower_boundary_is_closer const diyfp m_minus = lower_boundary_is_closer
? diyfp(4 * v.f - 1, v.e - 2) // (B) ? diyfp(4 * v.f - 1, v.e - 2) // (B)
......
...@@ -91,10 +91,8 @@ class binary_reader ...@@ -91,10 +91,8 @@ class binary_reader
result = parse_ubjson_internal(); result = parse_ubjson_internal();
break; break;
// LCOV_EXCL_START default: // LCOV_EXCL_LINE
default: assert(false); // LCOV_EXCL_LINE
assert(false);
// LCOV_EXCL_STOP
} }
// strict mode: next byte must be EOF // strict mode: next byte must be EOF
...@@ -128,7 +126,7 @@ class binary_reader ...@@ -128,7 +126,7 @@ class binary_reader
*/ */
static constexpr bool little_endianess(int num = 1) noexcept static constexpr bool little_endianess(int num = 1) noexcept
{ {
return (*reinterpret_cast<char*>(&num) == 1); return *reinterpret_cast<char*>(&num) == 1;
} }
private: private:
...@@ -305,12 +303,9 @@ class binary_reader ...@@ -305,12 +303,9 @@ class binary_reader
return false; return false;
} }
if (not is_array) if (not is_array and not sax->key(key))
{ {
if (not sax->key(key)) return false;
{
return false;
}
} }
if (JSON_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position))) if (JSON_UNLIKELY(not parse_bson_element_internal(element_type, element_type_parse_position)))
...@@ -1818,7 +1813,7 @@ class binary_reader ...@@ -1818,7 +1813,7 @@ class binary_reader
int get() int get()
{ {
++chars_read; ++chars_read;
return (current = ia->get_character()); return current = ia->get_character();
} }
/*! /*!
...@@ -1964,10 +1959,8 @@ class binary_reader ...@@ -1964,10 +1959,8 @@ class binary_reader
error_msg += "BSON"; error_msg += "BSON";
break; break;
// LCOV_EXCL_START default: // LCOV_EXCL_LINE
default: assert(false); // LCOV_EXCL_LINE
assert(false);
// LCOV_EXCL_STOP
} }
return error_msg + " " + context + ": " + detail; return error_msg + " " + context + ": " + detail;
......
...@@ -286,7 +286,7 @@ template<typename WideStringType> ...@@ -286,7 +286,7 @@ template<typename WideStringType>
class wide_string_input_adapter : public input_adapter_protocol class wide_string_input_adapter : public input_adapter_protocol
{ {
public: public:
explicit wide_string_input_adapter(const WideStringType& w) noexcept explicit wide_string_input_adapter(const WideStringType& w) noexcept
: str(w) : str(w)
{} {}
......
...@@ -303,12 +303,11 @@ class json_sax_dom_parser ...@@ -303,12 +303,11 @@ class json_sax_dom_parser
ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v)); ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
return &(ref_stack.back()->m_value.array->back()); return &(ref_stack.back()->m_value.array->back());
} }
else
{ assert(ref_stack.back()->is_object())
assert(object_element); assert(object_element);
*object_element = BasicJsonType(std::forward<Value>(v)); *object_element = BasicJsonType(std::forward<Value>(v));
return object_element; return object_element;
}
} }
/// the parsed JSON value /// the parsed JSON value
...@@ -395,13 +394,9 @@ class json_sax_dom_callback_parser ...@@ -395,13 +394,9 @@ class json_sax_dom_callback_parser
ref_stack.push_back(val.second); ref_stack.push_back(val.second);
// check object limit // check object limit
if (ref_stack.back()) if (ref_stack.back() and JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
{ {
if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len)));
{
JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len)));
}
} }
return true; return true;
...@@ -426,13 +421,10 @@ class json_sax_dom_callback_parser ...@@ -426,13 +421,10 @@ class json_sax_dom_callback_parser
bool end_object() bool end_object()
{ {
if (ref_stack.back()) if (ref_stack.back() and not callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
{ {
if (not callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back())) // discard object
{ *ref_stack.back() = discarded;
// discard object
*ref_stack.back() = discarded;
}
} }
assert(not ref_stack.empty()); assert(not ref_stack.empty());
...@@ -440,18 +432,15 @@ class json_sax_dom_callback_parser ...@@ -440,18 +432,15 @@ class json_sax_dom_callback_parser
ref_stack.pop_back(); ref_stack.pop_back();
keep_stack.pop_back(); keep_stack.pop_back();
if (not ref_stack.empty() and ref_stack.back()) if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object())
{ {
// remove discarded value // remove discarded value
if (ref_stack.back()->is_object()) for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
{ {
for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it) if (it->is_discarded())
{ {
if (it->is_discarded()) ref_stack.back()->erase(it);
{ break;
ref_stack.back()->erase(it);
break;
}
} }
} }
} }
...@@ -468,13 +457,9 @@ class json_sax_dom_callback_parser ...@@ -468,13 +457,9 @@ class json_sax_dom_callback_parser
ref_stack.push_back(val.second); ref_stack.push_back(val.second);
// check array limit // check array limit
if (ref_stack.back()) if (ref_stack.back() and JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size()))
{ {
if (JSON_UNLIKELY(len != std::size_t(-1) and len > ref_stack.back()->max_size())) JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len)));
{
JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len)));
}
} }
return true; return true;
...@@ -500,12 +485,9 @@ class json_sax_dom_callback_parser ...@@ -500,12 +485,9 @@ class json_sax_dom_callback_parser
keep_stack.pop_back(); keep_stack.pop_back();
// remove discarded value // remove discarded value
if (not keep and not ref_stack.empty()) if (not keep and not ref_stack.empty() and ref_stack.back()->is_array())
{ {
if (ref_stack.back()->is_array()) ref_stack.back()->m_value.array->pop_back();
{
ref_stack.back()->m_value.array->pop_back();
}
} }
return true; return true;
...@@ -600,27 +582,28 @@ class json_sax_dom_callback_parser ...@@ -600,27 +582,28 @@ class json_sax_dom_callback_parser
// we now only expect arrays and objects // we now only expect arrays and objects
assert(ref_stack.back()->is_array() or ref_stack.back()->is_object()); assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
// array
if (ref_stack.back()->is_array()) if (ref_stack.back()->is_array())
{ {
ref_stack.back()->m_value.array->push_back(std::move(value)); ref_stack.back()->m_value.array->push_back(std::move(value));
return {true, &(ref_stack.back()->m_value.array->back())}; return {true, &(ref_stack.back()->m_value.array->back())};
} }
else
{
// check if we should store an element for the current key
assert(not key_keep_stack.empty());
const bool store_element = key_keep_stack.back();
key_keep_stack.pop_back();
if (not store_element) // object
{ assert(ref_stack.back()->is_object())
return {false, nullptr}; // check if we should store an element for the current key
} assert(not key_keep_stack.empty());
const bool store_element = key_keep_stack.back();
key_keep_stack.pop_back();
assert(object_element); if (not store_element)
*object_element = std::move(value); {
return {true, object_element}; return {false, nullptr};
} }
assert(object_element);
*object_element = std::move(value);
return {true, object_element};
} }
/// the parsed JSON value /// the parsed JSON value
......
...@@ -908,13 +908,9 @@ class lexer ...@@ -908,13 +908,9 @@ class lexer
goto scan_number_any1; goto scan_number_any1;
} }
// LCOV_EXCL_START // all other characters are rejected outside scan_number()
default: default: // LCOV_EXCL_LINE
{ assert(false); // LCOV_EXCL_LINE
// all other characters are rejected outside scan_number()
assert(false);
}
// LCOV_EXCL_STOP
} }
scan_number_minus: scan_number_minus:
......
...@@ -459,7 +459,7 @@ class parser ...@@ -459,7 +459,7 @@ class parser
/// get next token from lexer /// get next token from lexer
token_type get_token() token_type get_token()
{ {
return (last_token = m_lexer.scan()); return last_token = m_lexer.scan();
} }
std::string exception_message(const token_type expected, const std::string& context) std::string exception_message(const token_type expected, const std::string& context)
......
...@@ -344,7 +344,7 @@ class json_pointer ...@@ -344,7 +344,7 @@ class json_pointer
std::all_of(reference_token.begin(), reference_token.end(), std::all_of(reference_token.begin(), reference_token.end(),
[](const char x) [](const char x)
{ {
return (x >= '0' and x <= '9'); return x >= '0' and x <= '9';
}); });
// change value to array for numbers or "-" or to object otherwise // change value to array for numbers or "-" or to object otherwise
...@@ -793,7 +793,7 @@ class json_pointer ...@@ -793,7 +793,7 @@ class json_pointer
friend bool operator==(json_pointer const& lhs, friend bool operator==(json_pointer const& lhs,
json_pointer const& rhs) noexcept json_pointer const& rhs) noexcept
{ {
return (lhs.reference_tokens == rhs.reference_tokens); return lhs.reference_tokens == rhs.reference_tokens;
} }
friend bool operator!=(json_pointer const& lhs, friend bool operator!=(json_pointer const& lhs,
......
...@@ -88,8 +88,8 @@ ...@@ -88,8 +88,8 @@
// manual branch prediction // manual branch prediction
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#define JSON_LIKELY(x) __builtin_expect(!!(x), 1) #define JSON_LIKELY(x) __builtin_expect(static_cast<bool>(x), 1)
#define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0) #define JSON_UNLIKELY(x) __builtin_expect(static_cast<bool>(x), 0)
#else #else
#define JSON_LIKELY(x) x #define JSON_LIKELY(x) x
#define JSON_UNLIKELY(x) x #define JSON_UNLIKELY(x) x
......
...@@ -279,10 +279,8 @@ class serializer ...@@ -279,10 +279,8 @@ class serializer
return; return;
} }
default: default: // LCOV_EXCL_LINE
{
assert(false); // LCOV_EXCL_LINE assert(false); // LCOV_EXCL_LINE
}
} }
} }
...@@ -480,10 +478,8 @@ class serializer ...@@ -480,10 +478,8 @@ class serializer
break; break;
} }
default: default: // LCOV_EXCL_LINE
{
assert(false); // LCOV_EXCL_LINE assert(false); // LCOV_EXCL_LINE
}
} }
break; break;
} }
...@@ -545,10 +541,8 @@ class serializer ...@@ -545,10 +541,8 @@ class serializer
break; break;
} }
default: default: // LCOV_EXCL_LINE
{
assert(false); // LCOV_EXCL_LINE assert(false); // LCOV_EXCL_LINE
}
} }
} }
} }
...@@ -755,7 +749,7 @@ class serializer ...@@ -755,7 +749,7 @@ class serializer
std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
[](char c) [](char c)
{ {
return (c == '.' or c == 'e'); return c == '.' or c == 'e';
}); });
if (value_is_int_like) if (value_is_int_like)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment