🔨 clean up
This commit is contained in:
		
							parent
							
								
									9fc093c9e0
								
							
						
					
					
						commit
						8d3f4f21bc
					
				
					 11 changed files with 432 additions and 512 deletions
				
			
		| 
						 | 
				
			
			@ -204,7 +204,7 @@ boundaries compute_boundaries(FloatType value)
 | 
			
		|||
    const std::uint64_t E = bits >> (kPrecision - 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
 | 
			
		||||
                    ? diyfp(F, kMinExp)
 | 
			
		||||
                    : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
 | 
			
		||||
| 
						 | 
				
			
			@ -230,7 +230,7 @@ boundaries compute_boundaries(FloatType value)
 | 
			
		|||
    //      -----------------+------+------+-------------+-------------+---  (B)
 | 
			
		||||
    //                       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_minus = lower_boundary_is_closer
 | 
			
		||||
                          ? diyfp(4 * v.f - 1, v.e - 2)  // (B)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,10 +91,8 @@ class binary_reader
 | 
			
		|||
                result = parse_ubjson_internal();
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            // LCOV_EXCL_START
 | 
			
		||||
            default:
 | 
			
		||||
                assert(false);
 | 
			
		||||
                // LCOV_EXCL_STOP
 | 
			
		||||
            default:            // LCOV_EXCL_LINE
 | 
			
		||||
                assert(false);  // LCOV_EXCL_LINE
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // strict mode: next byte must be EOF
 | 
			
		||||
| 
						 | 
				
			
			@ -128,7 +126,7 @@ class binary_reader
 | 
			
		|||
    */
 | 
			
		||||
    static constexpr bool little_endianess(int num = 1) noexcept
 | 
			
		||||
    {
 | 
			
		||||
        return (*reinterpret_cast<char*>(&num) == 1);
 | 
			
		||||
        return *reinterpret_cast<char*>(&num) == 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
| 
						 | 
				
			
			@ -305,12 +303,9 @@ class binary_reader
 | 
			
		|||
                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)))
 | 
			
		||||
| 
						 | 
				
			
			@ -1818,7 +1813,7 @@ class binary_reader
 | 
			
		|||
    int get()
 | 
			
		||||
    {
 | 
			
		||||
        ++chars_read;
 | 
			
		||||
        return (current = ia->get_character());
 | 
			
		||||
        return current = ia->get_character();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*!
 | 
			
		||||
| 
						 | 
				
			
			@ -1964,10 +1959,8 @@ class binary_reader
 | 
			
		|||
                error_msg += "BSON";
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            // LCOV_EXCL_START
 | 
			
		||||
            default:
 | 
			
		||||
                assert(false);
 | 
			
		||||
                // LCOV_EXCL_STOP
 | 
			
		||||
            default:            // LCOV_EXCL_LINE
 | 
			
		||||
                assert(false);  // LCOV_EXCL_LINE
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return error_msg + " " + context + ": " + detail;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -286,7 +286,7 @@ template<typename WideStringType>
 | 
			
		|||
class wide_string_input_adapter : public input_adapter_protocol
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    explicit wide_string_input_adapter(const WideStringType& w)  noexcept
 | 
			
		||||
    explicit wide_string_input_adapter(const WideStringType& w) noexcept
 | 
			
		||||
        : str(w)
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -303,12 +303,11 @@ class json_sax_dom_parser
 | 
			
		|||
            ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
 | 
			
		||||
            return &(ref_stack.back()->m_value.array->back());
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            assert(object_element);
 | 
			
		||||
            *object_element = BasicJsonType(std::forward<Value>(v));
 | 
			
		||||
            return object_element;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        assert(ref_stack.back()->is_object())
 | 
			
		||||
        assert(object_element);
 | 
			
		||||
        *object_element = BasicJsonType(std::forward<Value>(v));
 | 
			
		||||
        return object_element;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// the parsed JSON value
 | 
			
		||||
| 
						 | 
				
			
			@ -395,13 +394,9 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        ref_stack.push_back(val.second);
 | 
			
		||||
 | 
			
		||||
        // 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;
 | 
			
		||||
| 
						 | 
				
			
			@ -426,13 +421,10 @@ class json_sax_dom_callback_parser
 | 
			
		|||
 | 
			
		||||
    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());
 | 
			
		||||
| 
						 | 
				
			
			@ -440,18 +432,15 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        ref_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
 | 
			
		||||
            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
 | 
			
		|||
        ref_stack.push_back(val.second);
 | 
			
		||||
 | 
			
		||||
        // 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;
 | 
			
		||||
| 
						 | 
				
			
			@ -500,12 +485,9 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        keep_stack.pop_back();
 | 
			
		||||
 | 
			
		||||
        // 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;
 | 
			
		||||
| 
						 | 
				
			
			@ -600,27 +582,28 @@ class json_sax_dom_callback_parser
 | 
			
		|||
        // we now only expect arrays and objects
 | 
			
		||||
        assert(ref_stack.back()->is_array() or ref_stack.back()->is_object());
 | 
			
		||||
 | 
			
		||||
        // array
 | 
			
		||||
        if (ref_stack.back()->is_array())
 | 
			
		||||
        {
 | 
			
		||||
            ref_stack.back()->m_value.array->push_back(std::move(value));
 | 
			
		||||
            return {true, &(ref_stack.back()->m_value.array->back())};
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
 | 
			
		||||
        // object
 | 
			
		||||
        assert(ref_stack.back()->is_object())
 | 
			
		||||
        // 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)
 | 
			
		||||
        {
 | 
			
		||||
            // 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)
 | 
			
		||||
            {
 | 
			
		||||
                return {false, nullptr};
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            assert(object_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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -908,13 +908,9 @@ class lexer
 | 
			
		|||
                goto scan_number_any1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // LCOV_EXCL_START
 | 
			
		||||
            default:
 | 
			
		||||
            {
 | 
			
		||||
                // all other characters are rejected outside scan_number()
 | 
			
		||||
                assert(false);
 | 
			
		||||
            }
 | 
			
		||||
                // LCOV_EXCL_STOP
 | 
			
		||||
            // all other characters are rejected outside scan_number()
 | 
			
		||||
            default:            // LCOV_EXCL_LINE
 | 
			
		||||
                assert(false);  // LCOV_EXCL_LINE
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
scan_number_minus:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -459,7 +459,7 @@ class parser
 | 
			
		|||
    /// get next token from lexer
 | 
			
		||||
    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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -344,7 +344,7 @@ class json_pointer
 | 
			
		|||
                    std::all_of(reference_token.begin(), reference_token.end(),
 | 
			
		||||
                                [](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
 | 
			
		||||
| 
						 | 
				
			
			@ -793,7 +793,7 @@ class json_pointer
 | 
			
		|||
    friend bool operator==(json_pointer const& lhs,
 | 
			
		||||
                           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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,8 +88,8 @@
 | 
			
		|||
 | 
			
		||||
// manual branch prediction
 | 
			
		||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
 | 
			
		||||
    #define JSON_LIKELY(x)      __builtin_expect(!!(x), 1)
 | 
			
		||||
    #define JSON_UNLIKELY(x)    __builtin_expect(!!(x), 0)
 | 
			
		||||
    #define JSON_LIKELY(x)      __builtin_expect(static_cast<bool>(x), 1)
 | 
			
		||||
    #define JSON_UNLIKELY(x)    __builtin_expect(static_cast<bool>(x), 0)
 | 
			
		||||
#else
 | 
			
		||||
    #define JSON_LIKELY(x)      x
 | 
			
		||||
    #define JSON_UNLIKELY(x)    x
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -279,10 +279,8 @@ class serializer
 | 
			
		|||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            default:
 | 
			
		||||
            {
 | 
			
		||||
            default:            // LCOV_EXCL_LINE
 | 
			
		||||
                assert(false);  // LCOV_EXCL_LINE
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -480,10 +478,8 @@ class serializer
 | 
			
		|||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        default:
 | 
			
		||||
                        {
 | 
			
		||||
                        default:            // LCOV_EXCL_LINE
 | 
			
		||||
                            assert(false);  // LCOV_EXCL_LINE
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -545,10 +541,8 @@ class serializer
 | 
			
		|||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                default:
 | 
			
		||||
                {
 | 
			
		||||
                default:            // LCOV_EXCL_LINE
 | 
			
		||||
                    assert(false);  // LCOV_EXCL_LINE
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -755,7 +749,7 @@ class serializer
 | 
			
		|||
            std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
 | 
			
		||||
                         [](char c)
 | 
			
		||||
        {
 | 
			
		||||
            return (c == '.' or c == 'e');
 | 
			
		||||
            return c == '.' or c == 'e';
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        if (value_is_int_like)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue