diff --git a/include/simdjson/dom/element.h b/include/simdjson/dom/element.h index 6d9af51d..acd466fc 100644 --- a/include/simdjson/dom/element.h +++ b/include/simdjson/dom/element.h @@ -455,7 +455,7 @@ public: really_inline simdjson_result type() const noexcept; template - really_inline simdjson_result is() const noexcept; + really_inline bool is() const noexcept; template really_inline simdjson_result get() const noexcept; template @@ -470,14 +470,14 @@ public: really_inline simdjson_result get_double() const noexcept; really_inline simdjson_result get_bool() const noexcept; - really_inline simdjson_result is_array() const noexcept; - really_inline simdjson_result is_object() const noexcept; - really_inline simdjson_result is_string() const noexcept; - really_inline simdjson_result is_int64_t() const noexcept; - really_inline simdjson_result is_uint64_t() const noexcept; - really_inline simdjson_result is_double() const noexcept; - really_inline simdjson_result is_bool() const noexcept; - really_inline simdjson_result is_null() const noexcept; + really_inline bool is_array() const noexcept; + really_inline bool is_object() const noexcept; + really_inline bool is_string() const noexcept; + really_inline bool is_int64_t() const noexcept; + really_inline bool is_uint64_t() const noexcept; + really_inline bool is_double() const noexcept; + really_inline bool is_bool() const noexcept; + really_inline bool is_null() const noexcept; really_inline simdjson_result operator[](const std::string_view &key) const noexcept; really_inline simdjson_result operator[](const char *key) const noexcept; diff --git a/include/simdjson/inline/element.h b/include/simdjson/inline/element.h index 690f40ff..fc983eed 100644 --- a/include/simdjson/inline/element.h +++ b/include/simdjson/inline/element.h @@ -24,9 +24,8 @@ inline simdjson_result simdjson_result::type() } template -really_inline simdjson_result simdjson_result::is() const noexcept { - if (error()) { return error(); } - return first.is(); +really_inline bool simdjson_result::is() const noexcept { + return !error() && first.is(); } template really_inline simdjson_result simdjson_result::get() const noexcept { @@ -72,38 +71,30 @@ really_inline simdjson_result simdjson_result::get_bool() co return first.get_bool(); } -really_inline simdjson_result simdjson_result::is_array() const noexcept { - if (error()) { return error(); } - return first.is_array(); +really_inline bool simdjson_result::is_array() const noexcept { + return !error() && first.is_array(); } -really_inline simdjson_result simdjson_result::is_object() const noexcept { - if (error()) { return error(); } - return first.is_object(); +really_inline bool simdjson_result::is_object() const noexcept { + return !error() && first.is_object(); } -really_inline simdjson_result simdjson_result::is_string() const noexcept { - if (error()) { return error(); } - return first.is_string(); +really_inline bool simdjson_result::is_string() const noexcept { + return !error() && first.is_string(); } -really_inline simdjson_result simdjson_result::is_int64_t() const noexcept { - if (error()) { return error(); } - return first.is_int64_t(); +really_inline bool simdjson_result::is_int64_t() const noexcept { + return !error() && first.is_int64_t(); } -really_inline simdjson_result simdjson_result::is_uint64_t() const noexcept { - if (error()) { return error(); } - return first.is_uint64_t(); +really_inline bool simdjson_result::is_uint64_t() const noexcept { + return !error() && first.is_uint64_t(); } -really_inline simdjson_result simdjson_result::is_double() const noexcept { - if (error()) { return error(); } - return first.is_double(); +really_inline bool simdjson_result::is_double() const noexcept { + return !error() && first.is_double(); } -really_inline simdjson_result simdjson_result::is_bool() const noexcept { - if (error()) { return error(); } - return first.is_bool(); +really_inline bool simdjson_result::is_bool() const noexcept { + return !error() && first.is_bool(); } -really_inline simdjson_result simdjson_result::is_null() const noexcept { - if (error()) { return error(); } - return first.is_null(); +really_inline bool simdjson_result::is_null() const noexcept { + return !error() && first.is_null(); } really_inline simdjson_result simdjson_result::operator[](const std::string_view &key) const noexcept { diff --git a/tests/basictests.cpp b/tests/basictests.cpp index d89eb5a9..ec7fe553 100644 --- a/tests/basictests.cpp +++ b/tests/basictests.cpp @@ -1503,27 +1503,9 @@ namespace type_tests { std::cout << " test_is_null() expecting " << expected_is_null << std::endl; // Grab the element out and check success dom::element element = result.first; - bool actual_is_null; - auto error = result.is_null().get(actual_is_null); - ASSERT_SUCCESS(error); - ASSERT_EQUAL(actual_is_null, expected_is_null); + ASSERT_EQUAL(result.is_null(), expected_is_null); - actual_is_null = element.is_null(); - ASSERT_EQUAL(actual_is_null, expected_is_null); - -#if SIMDJSON_EXCEPTIONS - - try { - - actual_is_null = result.is_null(); - ASSERT_EQUAL(actual_is_null, expected_is_null); - - } catch(simdjson_error &e) { - std::cerr << e.error() << std::endl; - return false; - } - -#endif // SIMDJSON_EXCEPTIONS + ASSERT_EQUAL(element.is_null(), expected_is_null); return true; } diff --git a/tests/cast_tester.h b/tests/cast_tester.h index 00e90de7..55eda96a 100644 --- a/tests/cast_tester.h +++ b/tests/cast_tester.h @@ -40,7 +40,6 @@ public: bool test_is(element element, bool expected); bool test_is(simdjson_result element, bool expected); - bool test_is_error(simdjson_result element, error_code expected_error); bool test_named_get(element element, T expected = {}); bool test_named_get(simdjson_result element, T expected = {}); @@ -49,13 +48,12 @@ public: bool test_named_is(element element, bool expected); bool test_named_is(simdjson_result element, bool expected); - bool test_named_is_error(simdjson_result element, error_code expected_error); private: simdjson_result named_get(element element); simdjson_result named_get(simdjson_result element); bool named_is(element element); - simdjson_result named_is(simdjson_result element); + bool named_is(simdjson_result element); bool assert_equal(const T& expected, const T& actual); }; @@ -206,16 +204,7 @@ bool cast_tester::test_is(element element, bool expected) { template bool cast_tester::test_is(simdjson_result element, bool expected) { - bool actual; - ASSERT_SUCCESS(element.is().get(actual)); - ASSERT_EQUAL(actual, expected); - return true; -} - -template -bool cast_tester::test_is_error(simdjson_result element, error_code expected_error) { - UNUSED bool actual; - ASSERT_EQUAL(element.is().get(actual), expected_error); + ASSERT_EQUAL(element.is(), expected); return true; } @@ -227,16 +216,7 @@ bool cast_tester::test_named_is(element element, bool expected) { template bool cast_tester::test_named_is(simdjson_result element, bool expected) { - bool actual; - ASSERT_SUCCESS(named_is(element).get(actual)); - ASSERT_EQUAL(actual, expected); - return true; -} - -template -bool cast_tester::test_named_is_error(simdjson_result element, error_code expected_error) { - bool actual; - ASSERT_EQUAL(named_is(element).get(actual), expected_error); + ASSERT_EQUAL(named_is(element), expected); return true; } @@ -267,14 +247,14 @@ template<> bool cast_tester::named_is(element element) { return element template<> bool cast_tester::named_is(element element) { return element.is_double(); } template<> bool cast_tester::named_is(element element) { return element.is_bool(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_array(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_object(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_string(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_string(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_uint64_t(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_int64_t(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_double(); } -template<> simdjson_result cast_tester::named_is(simdjson_result element) { return element.is_bool(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_array(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_object(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_string(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_string(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_uint64_t(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_int64_t(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_double(); } +template<> bool cast_tester::named_is(simdjson_result element) { return element.is_bool(); } template bool cast_tester::assert_equal(const T& expected, const T& actual) { ASSERT_EQUAL(expected, actual);