diff --git a/Benchmarks/Tests.hpp b/Benchmarks/Tests.hpp index d60b84692..f125e43be 100644 --- a/Benchmarks/Tests.hpp +++ b/Benchmarks/Tests.hpp @@ -96,7 +96,7 @@ namespace tests { static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read-Raw-Json-Data" }; static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write-Raw-Json-Data" }; static constexpr bool partialRead{ std::is_same_v> || std::is_same_v }; - static constexpr bool knownOrder{ !std::is_same_v && !std::is_same_v> }; + static constexpr bool knownOrder{ true }; std::vector newStrings{ iterations }; results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl }; jsonifier::jsonifier_core parser{}; @@ -166,7 +166,7 @@ namespace tests { static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" }; static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" }; static constexpr bool partialRead{ std::is_same_v> || std::is_same_v }; - static constexpr bool knownOrder{ !std::is_same_v && !std::is_same_v> }; + static constexpr bool knownOrder{ true }; results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl }; jsonifier::jsonifier_core parser{}; std::vector> newStrings{ iterations }; @@ -217,7 +217,7 @@ namespace tests { }); r.readResult = result{ "teal", readResult }; r.writeResult = result{ "steelblue", writeResult }; - bnch_swt::file_loader::saveFile(static_cast(parser.serializeJson(testDatas[0])), + bnch_swt::file_loader::saveFile(static_cast(parser.serializeJson(testDatas)), jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-jsonifier.json"); return r; } @@ -230,7 +230,7 @@ namespace tests { static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" }; static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" }; static constexpr bool partialRead{ std::is_same_v> || std::is_same_v }; - static constexpr bool knownOrder{ !std::is_same_v && !std::is_same_v> }; + static constexpr bool knownOrder{ true }; results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl }; jsonifier::jsonifier_core parser{}; std::vector newStrings{ iterations }; @@ -278,7 +278,7 @@ namespace tests { static constexpr bnch_swt::string_literal testNameRead{ testName + "-Read" }; static constexpr bnch_swt::string_literal testNameWrite{ testName + "-Write" }; static constexpr bool partialRead{ std::is_same_v> || std::is_same_v }; - static constexpr bool knownOrder{ !std::is_same_v && !std::is_same_v> }; + static constexpr bool knownOrder{ true }; results_data r{ jsonifierLibraryName, testName, jsonifierCommitUrl }; jsonifier::jsonifier_core parser{}; std::vector newStrings{ iterations }; @@ -422,7 +422,8 @@ namespace tests { testDatas[x].resize(testDataNew[x].size()); } size_t currentIndex{}; - bnch_swt::performance_metrics readResult = bnch_swt::benchmark_stage::template runBenchmark([&]() mutable { + bnch_swt::performance_metrics readResult = + bnch_swt::benchmark_stage::template runBenchmark([&]() mutable { size_t newSize{}; for (size_t x = 0; x < testDatas[currentIndex].size(); ++x) { get_ref_t reference = testDatas[currentIndex][x]; @@ -439,7 +440,7 @@ namespace tests { } ++currentIndex; return newSize; - }); + }); for (size_t x = 0; x < iterations; ++x) { for (size_t y = 0; y < testDataNew[x].size(); ++y) { newStrings[x][y] = std::string{}; @@ -462,7 +463,7 @@ namespace tests { r.readResult = result{ "dodgerblue", readResult }; r.writeResult = result{ "skyblue", writeResult }; std::string newString{}; - auto newResult = glz::write_json(testDatas[0], newString); + auto newResult = glz::write_json(testDatas, newString); ( void )newResult; bnch_swt::file_loader::saveFile(newString, jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-glaze.json"); return r; @@ -669,7 +670,7 @@ namespace tests { }); r.readResult = result{ "cadetblue", readResult }; std::string newString{}; - auto newResult = glz::write_json(testDatas[0], newString); + auto newResult = glz::write_json(testDatas, newString); ( void )newResult; bnch_swt::file_loader::saveFile(newString, jsonOutPath.operator std::string() + "/" + testName.operator std::string() + "-simdjson.json"); return r; @@ -994,21 +995,13 @@ In contrast, hash-based solutions offer a viable alternative by circumventing th JSONIFIER_CLANG_INLINE void testFunction() { std::string jsonDataNew{}; jsonifier::jsonifier_core parser{}; - std::vector jsonDataSmallNewer{ maxIterations }; - for (size_t x = 0; x < maxIterations; ++x) { - jsonDataSmallNewer[x] = test_generator::generateTestStruct(); - } std::vector> jsonDataNewer{ maxIterations }; for (size_t x = 0; x < maxIterations; ++x) { jsonDataNewer[x] = test_generator::generateTest(); } - parser.serializeJson(jsonDataSmallNewer[0], jsonDataNew); - bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Json Test (Small) (Prettified).json"); - std::string jsonMinifiedData{ parser.minifyJson(jsonDataNew) }; - bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Json Test (Small) (Minified).json"); parser.serializeJson(jsonDataNewer[0], jsonDataNew); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Json Test (Prettified).json"); - jsonMinifiedData = parser.minifyJson(jsonDataNew); + std::string jsonMinifiedData = parser.minifyJson(jsonDataNew); bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Json Test (Minified).json"); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Partial Test (Prettified).json"); bnch_swt::file_loader::saveFile(jsonMinifiedData, jsonOutPath.operator std::string() + "/Partial Test (Minified).json"); @@ -1023,51 +1016,45 @@ In contrast, hash-based solutions offer a viable alternative by circumventing th static_cast(section001) }; test_results testResults{}; { - std::vector> doubleData{ test_generator::generateValues(maxIterations, 2500) }; - parser.serializeJson(doubleData[0], jsonDataNew); + std::vector> doubleData{ test_generator::generateValues(maxIterations, 100) }; + parser.serializeJson(doubleData, jsonDataNew); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Double Test.json"); testResults = json_tests_helper>, false, maxIterations, "Double Test">::run(doubleData); newerString += testResults.markdownResults; benchmark_data.emplace_back(testResults); } { - std::vector> stringData{ test_generator::generateValues(maxIterations, 2500) }; - parser.serializeJson(stringData[0], jsonDataNew); + std::vector> stringData{ test_generator::generateValues(maxIterations, 100) }; + parser.serializeJson(stringData, jsonDataNew); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/String Test.json"); testResults = json_tests_helper>, false, maxIterations, "String Test">::run(stringData); newerString += testResults.markdownResults; benchmark_data.emplace_back(testResults); } { - std::vector> uintData{ test_generator::generateValues(maxIterations, 2500) }; - parser.serializeJson(uintData[0], jsonDataNew); + std::vector> uintData{ test_generator::generateValues(maxIterations, 100) }; + parser.serializeJson(uintData, jsonDataNew); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Uint Test.json"); testResults = json_tests_helper>, false, maxIterations, "Uint Test">::run(uintData); newerString += testResults.markdownResults; benchmark_data.emplace_back(testResults); } { - std::vector> intData{ test_generator::generateValues(maxIterations, 2500) }; - parser.serializeJson(intData[0], jsonDataNew); + std::vector> intData{ test_generator::generateValues(maxIterations, 100) }; + parser.serializeJson(intData, jsonDataNew); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Int Test.json"); testResults = json_tests_helper>, false, maxIterations, "Int Test">::run(intData); newerString += testResults.markdownResults; benchmark_data.emplace_back(testResults); } { - std::vector> boolData{ test_generator::generateValues(maxIterations, 2500) }; - parser.serializeJson(boolData[0], jsonDataNew); + std::vector> boolData{ test_generator::generateValues(maxIterations, 100) }; + parser.serializeJson(boolData, jsonDataNew); bnch_swt::file_loader::saveFile(jsonDataNew, jsonOutPath.operator std::string() + "/Bool Test.json"); testResults = json_tests_helper>, false, maxIterations, "Bool Test">::run(boolData); newerString += testResults.markdownResults; benchmark_data.emplace_back(testResults); } - testResults = json_tests_helper::run(jsonDataSmallNewer); - newerString += testResults.markdownResults; - benchmark_data.emplace_back(testResults); - testResults = json_tests_helper::run(jsonDataSmallNewer); - newerString += testResults.markdownResults; - benchmark_data.emplace_back(testResults); testResults = json_tests_helper, false, maxIterations, "Json Test (Prettified)">::run(jsonDataNewer); newerString += testResults.markdownResults; benchmark_data.emplace_back(testResults); diff --git a/Include/jsonifier/Containers/Array.hpp b/Include/jsonifier/Containers/Array.hpp index 7bedf9ad2..fccbe16e9 100644 --- a/Include/jsonifier/Containers/Array.hpp +++ b/Include/jsonifier/Containers/Array.hpp @@ -26,147 +26,7 @@ #include #include -namespace jsonifier::internal { - - template class array_iterator { - public: - using iterator_concept = std::contiguous_iterator_tag; - using iterator_category = std::random_access_iterator_tag; - using element_type = value_type_new; - using value_type = value_type_new; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - JSONIFIER_INLINE constexpr array_iterator() noexcept : ptr() { - } - - JSONIFIER_INLINE constexpr array_iterator(pointer ptrNew) noexcept : ptr(ptrNew) { - } - - JSONIFIER_INLINE constexpr reference operator*() const noexcept { - return *ptr; - } - - JSONIFIER_INLINE constexpr pointer operator->() const noexcept { - return std::pointer_traits::pointer_to(**this); - } - - JSONIFIER_INLINE constexpr array_iterator& operator++() noexcept { - ++ptr; - return *this; - } - - JSONIFIER_INLINE constexpr array_iterator operator++(int32_t) noexcept { - array_iterator temp = *this; - ++*this; - return temp; - } - - JSONIFIER_INLINE constexpr array_iterator& operator--() noexcept { - --ptr; - return *this; - } - - JSONIFIER_INLINE constexpr array_iterator operator--(int32_t) noexcept { - array_iterator temp = *this; - --*this; - return temp; - } - - JSONIFIER_INLINE constexpr array_iterator& operator+=(const difference_type offSet) noexcept { - ptr += offSet; - return *this; - } - - JSONIFIER_INLINE constexpr array_iterator operator+(const difference_type offSet) const noexcept { - array_iterator temp = *this; - temp += offSet; - return temp; - } - - JSONIFIER_INLINE friend constexpr array_iterator operator+(const difference_type offSet, array_iterator _Next) noexcept { - _Next += offSet; - return _Next; - } - - JSONIFIER_INLINE constexpr array_iterator& operator-=(const difference_type offSet) noexcept { - return *this += -offSet; - } - - JSONIFIER_INLINE constexpr array_iterator operator-(const difference_type offSet) const noexcept { - array_iterator temp = *this; - temp -= offSet; - return temp; - } - - JSONIFIER_INLINE constexpr difference_type operator-(const array_iterator& other) const noexcept { - return static_cast(ptr - other.ptr); - } - - JSONIFIER_INLINE constexpr reference operator[](const difference_type offSet) const noexcept { - return *(*this + offSet); - } - - JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept { - return ptr == other.ptr; - } - - JSONIFIER_INLINE constexpr std::strong_ordering operator<=>(const array_iterator& other) const noexcept { - return ptr <=> other.ptr; - } - - JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept { - return !(*this == other); - } - - JSONIFIER_INLINE constexpr bool operator<(const array_iterator& other) const noexcept { - return ptr < other.ptr; - } - - JSONIFIER_INLINE constexpr bool operator>(const array_iterator& other) const noexcept { - return other < *this; - } - - JSONIFIER_INLINE constexpr bool operator<=(const array_iterator& other) const noexcept { - return !(other < *this); - } - - JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept { - return !(*this < other); - } - - pointer ptr; - }; - - template class array_iterator { - public: - using iterator_concept = std::contiguous_iterator_tag; - using iterator_category = std::random_access_iterator_tag; - using element_type = value_type_new; - using value_type = value_type_new; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - JSONIFIER_INLINE constexpr array_iterator() noexcept { - } - - JSONIFIER_INLINE constexpr array_iterator(std::nullptr_t ptrNew) noexcept { - } - - JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept { - return true; - } - - JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept { - return !(*this == other); - } - - JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept { - return !(*this < other); - } - }; +namespace jsonifier::internal { template struct array { using value_type = value_type_new; diff --git a/Include/jsonifier/Containers/Iterator.hpp b/Include/jsonifier/Containers/Iterator.hpp index 8bb5fb18a..8ca0c6ec4 100644 --- a/Include/jsonifier/Containers/Iterator.hpp +++ b/Include/jsonifier/Containers/Iterator.hpp @@ -137,4 +137,144 @@ namespace jsonifier::internal { pointer ptr; }; + template class array_iterator { + public: + using iterator_concept = std::contiguous_iterator_tag; + using iterator_category = std::random_access_iterator_tag; + using element_type = value_type_new; + using value_type = value_type_new; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + JSONIFIER_INLINE constexpr array_iterator() noexcept : ptr() { + } + + JSONIFIER_INLINE constexpr array_iterator(pointer ptrNew) noexcept : ptr(ptrNew) { + } + + JSONIFIER_INLINE constexpr reference operator*() const noexcept { + return *ptr; + } + + JSONIFIER_INLINE constexpr pointer operator->() const noexcept { + return std::pointer_traits::pointer_to(**this); + } + + JSONIFIER_INLINE constexpr array_iterator& operator++() noexcept { + ++ptr; + return *this; + } + + JSONIFIER_INLINE constexpr array_iterator operator++(int32_t) noexcept { + array_iterator temp = *this; + ++*this; + return temp; + } + + JSONIFIER_INLINE constexpr array_iterator& operator--() noexcept { + --ptr; + return *this; + } + + JSONIFIER_INLINE constexpr array_iterator operator--(int32_t) noexcept { + array_iterator temp = *this; + --*this; + return temp; + } + + JSONIFIER_INLINE constexpr array_iterator& operator+=(const difference_type offSet) noexcept { + ptr += offSet; + return *this; + } + + JSONIFIER_INLINE constexpr array_iterator operator+(const difference_type offSet) const noexcept { + array_iterator temp = *this; + temp += offSet; + return temp; + } + + JSONIFIER_INLINE friend constexpr array_iterator operator+(const difference_type offSet, array_iterator _Next) noexcept { + _Next += offSet; + return _Next; + } + + JSONIFIER_INLINE constexpr array_iterator& operator-=(const difference_type offSet) noexcept { + return *this += -offSet; + } + + JSONIFIER_INLINE constexpr array_iterator operator-(const difference_type offSet) const noexcept { + array_iterator temp = *this; + temp -= offSet; + return temp; + } + + JSONIFIER_INLINE constexpr difference_type operator-(const array_iterator& other) const noexcept { + return static_cast(ptr - other.ptr); + } + + JSONIFIER_INLINE constexpr reference operator[](const difference_type offSet) const noexcept { + return *(*this + offSet); + } + + JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept { + return ptr == other.ptr; + } + + JSONIFIER_INLINE constexpr std::strong_ordering operator<=>(const array_iterator& other) const noexcept { + return ptr <=> other.ptr; + } + + JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept { + return !(*this == other); + } + + JSONIFIER_INLINE constexpr bool operator<(const array_iterator& other) const noexcept { + return ptr < other.ptr; + } + + JSONIFIER_INLINE constexpr bool operator>(const array_iterator& other) const noexcept { + return other < *this; + } + + JSONIFIER_INLINE constexpr bool operator<=(const array_iterator& other) const noexcept { + return !(other < *this); + } + + JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept { + return !(*this < other); + } + + pointer ptr; + }; + + template class array_iterator { + public: + using iterator_concept = std::contiguous_iterator_tag; + using iterator_category = std::random_access_iterator_tag; + using element_type = value_type_new; + using value_type = value_type_new; + using difference_type = std::ptrdiff_t; + using pointer = value_type*; + using reference = value_type&; + + JSONIFIER_INLINE constexpr array_iterator() noexcept { + } + + JSONIFIER_INLINE constexpr array_iterator(std::nullptr_t ptrNew) noexcept { + } + + JSONIFIER_INLINE constexpr bool operator==(const array_iterator& other) const noexcept { + return true; + } + + JSONIFIER_INLINE constexpr bool operator!=(const array_iterator& other) const noexcept { + return !(*this == other); + } + + JSONIFIER_INLINE constexpr bool operator>=(const array_iterator& other) const noexcept { + return !(*this < other); + } + }; + }// namespace internal \ No newline at end of file diff --git a/Include/jsonifier/Utilities/Compare.hpp b/Include/jsonifier/Utilities/Compare.hpp index ec469446d..868e1c9c7 100644 --- a/Include/jsonifier/Utilities/Compare.hpp +++ b/Include/jsonifier/Utilities/Compare.hpp @@ -455,7 +455,7 @@ namespace jsonifier::internal { #endif #if JSONIFIER_CHECK_FOR_INSTRUCTION(JSONIFIER_AVX512) - template struct string_literal_comparitor { + template struct string_literal_comparitor { JSONIFIER_INLINE static bool impl(string_view_ptr str) noexcept { static constexpr auto newLiteral{ stringNew }; JSONIFIER_ALIGN(64) static constexpr auto valuesNew{ packValues() }; diff --git a/Include/jsonifier/Utilities/Error.hpp b/Include/jsonifier/Utilities/Error.hpp index da1c7ad80..ea0f027f7 100644 --- a/Include/jsonifier/Utilities/Error.hpp +++ b/Include/jsonifier/Utilities/Error.hpp @@ -194,10 +194,6 @@ namespace jsonifier::internal { return returnValues; }() }; - static bool isNumberType(uint8_t c) noexcept { - return numberTable[c]; - } - static string convertChar(char value) { switch (value) { [[unlikely]] case '\b': { return R"(\b)"; } diff --git a/Include/jsonifier/Utilities/HashMap.hpp b/Include/jsonifier/Utilities/HashMap.hpp index d42eadcf0..097053552 100644 --- a/Include/jsonifier/Utilities/HashMap.hpp +++ b/Include/jsonifier/Utilities/HashMap.hpp @@ -567,7 +567,7 @@ namespace jsonifier::internal { template constexpr static auto generateMappingsForLengths(const tuple_references& keys, const array& uniqueIndices) noexcept { std::array mappings{}; - std::fill(mappings.data(), mappings.data() + mappings.size(), std::numeric_limits::max()); + std::fill(mappings.data(), mappings.data() + mappings.size(), static_cast(mappings.size() - 1)); for (size_t x = 0; x < keys.count; ++x) { const auto& key = keys.rootPtr[x].key; @@ -584,11 +584,21 @@ namespace jsonifier::internal { return mappings; } - template + template constexpr char getMaxFirstByte(const array& keys) noexcept { + char returnValue{}; + for (size_t x = 0; x < firstCharCount; ++x) { + if (keys[x].value > returnValue) { + returnValue = keys[x].value; + } + } + return returnValue; + } + + template constexpr static auto generateMappingsForFirstBytes(const array& keys, const array& uniqueIndices) noexcept { - constexpr size_t flattenedSize = 256ull * 256ull; + constexpr size_t flattenedSize = (maxFirstByte + 1) * 256ull; std::array flattenedMappings{}; - std::fill(flattenedMappings.data(), flattenedMappings.data() + flattenedMappings.size(), flattenedMappings.size() - 1); + std::fill(flattenedMappings.data(), flattenedMappings.data() + flattenedMappings.size(), static_cast(flattenedMappings.size() - 1)); for (size_t x = 0; x < firstCharCount; ++x) { const auto& key = keys[x].rootPtr[0].key; @@ -599,7 +609,7 @@ namespace jsonifier::internal { const auto& keyNew = keys[x].rootPtr[y].key; if (uniqueIndex < keyNew.size()) { uint8_t keyChar = static_cast(keyNew[uniqueIndex]); - size_t flattenedIdx = firstByte * 256ull + keyChar; + size_t flattenedIdx = static_cast(firstByte * maxFirstByte + keyChar); flattenedMappings[flattenedIdx] = keys[x].rootPtr[y].oldIndex; } } @@ -653,8 +663,8 @@ namespace jsonifier::internal { return hashData.storageSize; } else if constexpr (hashData.type == hash_map_type::first_byte_and_unique_index) { static constexpr auto uniqueFirstByteCount{ countFirstBytes(tupleReferencesByFirstByte) }; - static constexpr auto mappings{ generateMappingsForFirstBytes(collectFirstBytes(tupleReferencesByFirstByte), - hashData.uniqueIndices) }; + static constexpr auto firstBytes{ collectFirstBytes(tupleReferencesByFirstByte) }; + static constexpr auto mappings{ generateMappingsForFirstBytes(firstBytes, hashData.uniqueIndices) }; const uint8_t firstByte = static_cast(iter[0]); const uint8_t uniqueIdx = hashData.uniqueIndices[firstByte]; if JSONIFIER_LIKELY (checkForEnd(iter, end, uniqueIdx)) { diff --git a/Include/jsonifier/Utilities/IToStr.hpp b/Include/jsonifier/Utilities/IToStr.hpp index 067843150..d48417fb6 100644 --- a/Include/jsonifier/Utilities/IToStr.hpp +++ b/Include/jsonifier/Utilities/IToStr.hpp @@ -80,21 +80,16 @@ namespace jsonifier::internal { JSONIFIER_INLINE static void multiply(uint64_t& value, uint64_t expValue) noexcept { #if defined(__SIZEOF_INT128__) - const __uint128_t res = static_cast<__uint128_t>(value) * static_cast<__uint128_t>(expValue); - value = static_cast(res); + value = static_cast(static_cast<__uint128_t>(value) * static_cast<__uint128_t>(expValue) >> 64); return; #elif defined(_M_ARM64) && !defined(__MINGW32__) - uint64_t values; - values = __umulh(value, expValue); - value = value * expValue; + value = __umulh(value, expValue); return; #elif (defined(_WIN64) && !defined(__clang__)) - uint64_t values; - value = _umul128(value, expValue, &values); + ( void )_umul128(value, expValue, &value); return; #else - uint64_t values; - value = umul128Generic(value, expValue, &values); + umul128Generic(value, expValue, &value); return; #endif } @@ -107,30 +102,31 @@ namespace jsonifier::internal { template JSONIFIER_INLINE static char* toChars(char* buf, value_type value) noexcept { switch (fastDigitCount(value)) { case 20: { - static constexpr uint64_t multiplier01{ 109951163ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - const uint64_t tmp = value / 100000000ull; - const uint64_t low = value - tmp * 100000000ull; + static constexpr uint64_t multiplier01{ 184467440737 }; + static constexpr uint64_t multiplier02{ 109951163ull }; + static constexpr uint64_t multiplier03{ 5243ull }; + const uint64_t tmp = value / 100000000ULL; + const uint64_t low = value - tmp * 100000000ULL; const uint64_t high = tmp / 10000ull; const uint64_t mid = tmp - high * 10000ull; - uint64_t aabb = (high * multiplier01) >> 40ull; + uint64_t aabb = (high * multiplier02) >> 40ull; uint64_t ccdd = high - aabb * 10000ull; - uint64_t aa = (aabb * multiplier02) >> 19ull; - uint64_t cc = (ccdd * multiplier02) >> 19ull; + uint64_t aa = (aabb * multiplier03) >> 19ull; + uint64_t cc = (ccdd * multiplier03) >> 19ull; uint64_t bb = aabb - aa * 100ull; uint64_t dd = ccdd - cc * 100ull; std::memcpy(buf, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 2ull, int_tables::charTable02 + bb, 2ull); std::memcpy(buf + 4ull, int_tables::charTable02 + cc, 2ull); std::memcpy(buf + 6ull, int_tables::charTable02 + dd, 2ull); - aa = (mid * multiplier02) >> 19ull; + aa = (mid * multiplier03) >> 19ull; bb = mid - aa * 100ull; std::memcpy(buf + 8ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 10ull, int_tables::charTable02 + bb, 2ull); - aabb = (low * multiplier01) >> 40ull; + aabb = (low * multiplier02) >> 40ull; ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - cc = (ccdd * multiplier02) >> 19ull; + aa = (aabb * multiplier03) >> 19ull; + cc = (ccdd * multiplier03) >> 19ull; std::memcpy(buf + 12ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 14ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 16ull, int_tables::charTable02 + cc, 2ull); @@ -138,47 +134,46 @@ namespace jsonifier::internal { return buf + 20ull; } case 19: { - static constexpr uint64_t multiplier01{ 109951163ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - const uint64_t tmp = value / 100000000ull; - const uint64_t low = value - tmp * 100000000ull; + static constexpr uint64_t multiplier01{ 184467440737 }; + static constexpr uint64_t multiplier02{ 109951163ull }; + static constexpr uint64_t multiplier03{ 5243ull }; + const uint64_t tmp = value / 100000000ULL; + const uint64_t low = value - tmp * 100000000ULL; const uint64_t high = tmp / 10000ull; const uint64_t mid = tmp - high * 10000ull; - uint64_t aabb = (high * multiplier01) >> 40ull; + uint64_t aabb = (high * multiplier02) >> 40ull; uint64_t ccdd = high - aabb * 10000ull; - uint64_t aa = (aabb * multiplier02) >> 19ull; - uint64_t cc = (ccdd * multiplier02) >> 19ull; - uint64_t bb = aabb - aa * 100ull; - uint64_t dd = ccdd - cc * 100ull; + uint64_t aa = (aabb * multiplier03) >> 19ull; + uint64_t cc = (ccdd * multiplier03) >> 19ull; buf[0] = int_tables::charTable1[aa]; - std::memcpy(buf + 1ull, int_tables::charTable02 + bb, 2ull); + std::memcpy(buf + 1ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 3ull, int_tables::charTable02 + cc, 2ull); - std::memcpy(buf + 5ull, int_tables::charTable02 + dd, 2ull); - aa = (mid * multiplier02) >> 19ull; - bb = mid - aa * 100ull; - std::memcpy(buf + 7ull, int_tables::charTable02 + aa, 2ull); - std::memcpy(buf + 9ull, int_tables::charTable02 + bb, 2ull); - aabb = (low * multiplier01) >> 40ull; + std::memcpy(buf + 5ull, int_tables::charTable02 + ccdd - cc * 100ull, 2ull); + aa = (mid * multiplier03) >> 19ull; + std::memcpy(buf + 7, int_tables::charTable02 + aa, 2ull); + std::memcpy(buf + 9ull, int_tables::charTable02 + mid - aa * 100ull, 2ull); + aabb = (low * multiplier02) >> 40ull; ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - cc = (ccdd * multiplier02) >> 19ull; - std::memcpy(buf + 11ull, int_tables::charTable02 + aa, 2ull); + aa = (aabb * multiplier03) >> 19ull; + cc = (ccdd * multiplier03) >> 19ull; + std::memcpy(buf + 11, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 13ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 15ull, int_tables::charTable02 + cc, 2ull); std::memcpy(buf + 17ull, int_tables::charTable02 + ccdd - cc * 100ull, 2ull); return buf + 19ull; } case 18: { - static constexpr uint64_t multiplier01{ 429497ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - static constexpr uint64_t multiplier03{ 109951163ull }; - const uint64_t tmp = value / 100000000ull; - const uint64_t low = value - tmp * 100000000ull; + static constexpr uint64_t multiplier01{ 184467440737 }; + static constexpr uint64_t multiplier02{ 429497ull }; + static constexpr uint64_t multiplier03{ 5243ull }; + static constexpr uint64_t multiplier04{ 109951163ull }; + const uint64_t tmp = value / 100000000ULL; + const uint64_t low = value - tmp * 100000000ULL; const uint64_t high = tmp / 10000ull; const uint64_t mid = tmp - high * 10000ull; - uint64_t aa = (high * multiplier01) >> 32ull; + uint64_t aa = (high * multiplier02) >> 32ull; const uint64_t bbcc = high - aa * 10000ull; - uint64_t bb = (bbcc * multiplier02) >> 19ull; + uint64_t bb = (bbcc * multiplier03) >> 19ull; uint64_t cc = bbcc - bb * 100ull; std::memcpy(buf, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 2ull, int_tables::charTable02 + bb, 2ull); @@ -187,10 +182,10 @@ namespace jsonifier::internal { bb = mid - aa * 100ull; std::memcpy(buf + 6ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 8ull, int_tables::charTable02 + bb, 2ull); - const uint64_t aabb = (low * multiplier03) >> 40ull; + const uint64_t aabb = (low * multiplier04) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - cc = (ccdd * multiplier02) >> 19ull; + aa = (aabb * multiplier03) >> 19ull; + cc = (ccdd * multiplier03) >> 19ull; std::memcpy(buf + 10ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 12ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 14ull, int_tables::charTable02 + cc, 2ull); @@ -198,16 +193,17 @@ namespace jsonifier::internal { return buf + 18ull; } case 17: { - static constexpr uint64_t multiplier01{ 429497ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - static constexpr uint64_t multiplier03{ 109951163ull }; - const uint64_t tmp = value / 100000000ull; - const uint64_t low = value - tmp * 100000000ull; + static constexpr uint64_t multiplier01{ 184467440737 }; + static constexpr uint64_t multiplier02{ 429497ull }; + static constexpr uint64_t multiplier03{ 5243ull }; + static constexpr uint64_t multiplier04{ 109951163ull }; + const uint64_t tmp = value / 100000000ULL; + const uint64_t low = value - tmp * 100000000ULL; const uint64_t high = tmp / 10000ull; const uint64_t mid = tmp - high * 10000ull; - uint64_t aa = (high * multiplier01) >> 32ull; + uint64_t aa = (high * multiplier02) >> 32ull; const uint64_t bbcc = high - aa * 10000ull; - uint64_t bb = (bbcc * multiplier02) >> 19ull; + uint64_t bb = (bbcc * multiplier03) >> 19ull; uint64_t cc = bbcc - bb * 100ull; buf[0] = int_tables::charTable1[aa]; std::memcpy(buf + 1ull, int_tables::charTable02 + bb, 2ull); @@ -216,10 +212,10 @@ namespace jsonifier::internal { bb = mid - aa * 100ull; std::memcpy(buf + 5ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 7ull, int_tables::charTable02 + bb, 2ull); - const uint64_t aabb = (low * multiplier03) >> 40ull; + const uint64_t aabb = (low * multiplier04) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - cc = (ccdd * multiplier02) >> 19ull; + aa = (aabb * multiplier03) >> 19ull; + cc = (ccdd * multiplier03) >> 19ull; std::memcpy(buf + 9ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 11ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 13ull, int_tables::charTable02 + cc, 2ull); @@ -227,24 +223,24 @@ namespace jsonifier::internal { return buf + 17ull; } case 16: { - static constexpr uint64_t multiplier01{ 109951163ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - const uint64_t high = value / 100000000ull; - const uint64_t low = value - high * 100000000ull; - uint64_t aabb = (high * multiplier01) >> 40ull; - uint64_t ccdd = high - aabb * 10000ull; - uint64_t aa = (aabb * multiplier02) >> 19ull; - uint64_t cc = (ccdd * multiplier02) >> 19ull; - const uint64_t bb = aabb - aa * 100ull; - const uint64_t dd = ccdd - cc * 100ull; + const uint64_t high = value / 1000000000000ull; + const uint64_t low = value - high * 1000000000000ull; + static constexpr uint64_t multiplier01{ 5243ull }; + uint64_t aa = (high * multiplier01) >> 19ull; std::memcpy(buf, int_tables::charTable02 + aa, 2ull); - std::memcpy(buf + 2ull, int_tables::charTable02 + bb, 2ull); - std::memcpy(buf + 4ull, int_tables::charTable02 + cc, 2ull); - std::memcpy(buf + 6ull, int_tables::charTable02 + dd, 2ull); - aabb = (low * multiplier01) >> 40ull; - ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - cc = (ccdd * multiplier02) >> 19ull; + std::memcpy(buf + 2ull, int_tables::charTable02 + high - aa * 100ull, 2ull); + static constexpr uint64_t multiplier02{ 184467440737ULL }; + uint64_t high12 = low; + multiply(high12, multiplier02); + const uint64_t low12 = low - high12 * 100000000ULL; + static constexpr uint64_t multiplier03{ 109951163ull }; + aa = (high12 * multiplier01) >> 19ull; + std::memcpy(buf + 4ull, int_tables::charTable02 + aa, 2ull); + std::memcpy(buf + 6ull, int_tables::charTable02 + high12 - aa * 100ull, 2ull); + const uint64_t aabb = (low12 * multiplier03) >> 40ull; + const uint64_t ccdd = low12 - aabb * 10000ull; + aa = (aabb * multiplier01) >> 19ull; + const uint64_t cc = (ccdd * multiplier01) >> 19ull; std::memcpy(buf + 8ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 10ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 12ull, int_tables::charTable02 + cc, 2ull); @@ -252,24 +248,26 @@ namespace jsonifier::internal { return buf + 16ull; } case 15: { - static constexpr uint64_t multiplier01{ 109951163ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - const uint64_t high = value / 100000000ull; - const uint64_t low = value - high * 100000000ull; - uint64_t aabb = (high * multiplier01) >> 40ull; - uint64_t ccdd = high - aabb * 10000ull; - uint64_t aa = (aabb * multiplier02) >> 19ull; - uint64_t cc = (ccdd * multiplier02) >> 19ull; - const uint64_t bb = aabb - aa * 100ull; - const uint64_t dd = ccdd - cc * 100ull; - buf[0] = int_tables::charTable1[aa]; + static constexpr uint64_t multiplier01{ 184467440737ULL }; + uint64_t high = value; + multiply(high, multiplier01); + const uint64_t low = value - high * 100000000ULL; + static constexpr uint64_t multiplier02{ 109951163ull }; + static constexpr uint64_t multiplier03{ 5243ull }; + uint64_t aabb = (high * multiplier02) >> 40ull; + uint64_t ccdd = high - aabb * 10000ull; + uint64_t aa = (aabb * multiplier03) >> 19ull; + uint64_t cc = (ccdd * multiplier03) >> 19ull; + const uint64_t bb = aabb - aa * 100ull; + const uint64_t dd = ccdd - cc * 100ull; + buf[0] = int_tables::charTable1[aa]; std::memcpy(buf + 1ull, int_tables::charTable02 + bb, 2ull); std::memcpy(buf + 3ull, int_tables::charTable02 + cc, 2ull); std::memcpy(buf + 5ull, int_tables::charTable02 + dd, 2ull); - aabb = (low * multiplier01) >> 40ull; + aabb = (low * multiplier02) >> 40ull; ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - cc = (ccdd * multiplier02) >> 19ull; + aa = (aabb * multiplier03) >> 19ull; + cc = (ccdd * multiplier03) >> 19ull; std::memcpy(buf + 7ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 9ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 11ull, int_tables::charTable02 + cc, 2ull); @@ -277,22 +275,23 @@ namespace jsonifier::internal { return buf + 15ull; } case 14: { - static constexpr uint64_t multiplier01{ 429497ull }; - static constexpr uint64_t multiplier02{ 109951163ull }; + static constexpr uint64_t multiplier01{ 184467440737ULL }; + uint64_t high = value; + multiply(high, multiplier01); + const uint64_t low = value - high * 100000000ULL; + static constexpr uint64_t multiplier02{ 429497ull }; static constexpr uint64_t multiplier03{ 5243ull }; - const uint64_t high = value / 100000000ull; - const uint64_t low = value - high * 100000000ull; - uint64_t aa = (high * multiplier01) >> 32ull; + uint64_t aa = (high * multiplier02) >> 32ull; const uint64_t bbcc = high - aa * 10000ull; const uint64_t bb = (bbcc * multiplier03) >> 19ull; - uint64_t cc = bbcc - bb * 100ull; std::memcpy(buf, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 2ull, int_tables::charTable02 + bb, 2ull); - std::memcpy(buf + 4ull, int_tables::charTable02 + cc, 2ull); - const uint64_t aabb = (low * multiplier02) >> 40ull; + std::memcpy(buf + 4ull, int_tables::charTable02 + bbcc - bb * 100ull, 2ull); + static constexpr uint64_t multiplier04{ 109951163ull }; + const uint64_t aabb = (low * multiplier04) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; aa = (aabb * multiplier03) >> 19ull; - cc = (ccdd * multiplier03) >> 19ull; + const uint64_t cc = (ccdd * multiplier03) >> 19ull; std::memcpy(buf + 6ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 8ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 10ull, int_tables::charTable02 + cc, 2ull); @@ -300,22 +299,24 @@ namespace jsonifier::internal { return buf + 14ull; } case 13: { - static constexpr uint64_t multiplier01{ 429497ull }; - static constexpr uint64_t multiplier02{ 109951163ull }; - static constexpr uint64_t multiplier03{ 5243ull }; - const uint64_t high = value / 100000000ull; - const uint64_t low = value - high * 100000000ull; - uint64_t aa = (high * multiplier01) >> 32ull; + static constexpr uint64_t multiplier01{ 184467440737ULL }; + uint64_t high = value; + multiply(high, multiplier01); + const uint64_t low = value - high * 100000000ULL; + static constexpr uint64_t multiplier02{ 429497ull }; + static constexpr uint64_t multiplier03{ 109951163ull }; + static constexpr uint64_t multiplier04{ 5243ull }; + uint64_t aa = (high * multiplier02) >> 32ull; const uint64_t bbcc = high - aa * 10000ull; - const uint64_t bb = (bbcc * multiplier03) >> 19ull; + const uint64_t bb = (bbcc * multiplier04) >> 19ull; uint64_t cc = bbcc - bb * 100ull; buf[0] = int_tables::charTable1[aa]; std::memcpy(buf + 1ull, int_tables::charTable02 + bb, 2ull); std::memcpy(buf + 3ull, int_tables::charTable02 + cc, 2ull); - const uint64_t aabb = (low * multiplier02) >> 40ull; + const uint64_t aabb = (low * multiplier03) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier03) >> 19ull; - cc = (ccdd * multiplier03) >> 19ull; + aa = (aabb * multiplier04) >> 19ull; + cc = (ccdd * multiplier04) >> 19ull; std::memcpy(buf + 5ull, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 7ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 9ull, int_tables::charTable02 + cc, 2ull); @@ -323,17 +324,19 @@ namespace jsonifier::internal { return buf + 13ull; } case 12: { - static constexpr uint64_t multiplier01{ 109951163ull }; - static constexpr uint64_t multiplier02{ 5243ull }; - const uint64_t high = value / 100000000ull; - const uint64_t low = value - high * 100000000ull; - uint64_t aa = (high * multiplier02) >> 19ull; + static constexpr uint64_t multiplier01{ 184467440737ULL }; + uint64_t high = value; + multiply(high, multiplier01); + const uint64_t low = value - high * 100000000ULL; + static constexpr uint64_t multiplier02{ 109951163ull }; + static constexpr uint64_t multiplier03{ 5243ull }; + uint64_t aa = (high * multiplier03) >> 19ull; std::memcpy(buf, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 2ull, int_tables::charTable02 + high - aa * 100ull, 2ull); - const uint64_t aabb = (low * multiplier01) >> 40ull; + const uint64_t aabb = (low * multiplier02) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier02) >> 19ull; - const uint64_t cc = (ccdd * multiplier02) >> 19ull; + aa = (aabb * multiplier03) >> 19ull; + const uint64_t cc = (ccdd * multiplier03) >> 19ull; std::memcpy(buf + 4, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 6ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 8ull, int_tables::charTable02 + cc, 2ull); @@ -341,20 +344,20 @@ namespace jsonifier::internal { return buf + 12; } case 11: { - static constexpr uint64_t multiplier01{ 180143985ull }; - static constexpr uint64_t multiplier02{ 109951163ull }; - static constexpr uint64_t multiplier03{ 5243ull }; - uint64_t high{ value }; + static constexpr uint64_t multiplier01{ 184467440737ULL }; + uint64_t high = value; multiply(high, multiplier01); - high = high >> 54; - const uint64_t low = value - high * 100000000ull; - uint64_t aa = (high * multiplier03) >> 19ull; - buf[0] = int_tables::charTable1[aa]; + const uint64_t low = value - high * 100000000ULL; + static constexpr uint64_t multiplier02{ 5243ull }; + uint64_t aa = (high * multiplier02) >> 19ull; + buf[0] = int_tables::charTable1[aa]; std::memcpy(buf + 1ull, int_tables::charTable02 + high - aa * 100ull, 2ull); - const uint64_t aabb = (low * multiplier02) >> 40ull; + static constexpr uint64_t multiplier03{ 109951163ull }; + static constexpr uint64_t multiplier04{ 5243ull }; + const uint64_t aabb = (low * multiplier03) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier03) >> 19ull; - const uint64_t cc = (ccdd * multiplier03) >> 19ull; + aa = (aabb * multiplier04) >> 19ull; + const uint64_t cc = (ccdd * multiplier04) >> 19ull; std::memcpy(buf + 3, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 5ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 7ull, int_tables::charTable02 + cc, 2ull); @@ -362,21 +365,17 @@ namespace jsonifier::internal { return buf + 11; } case 10: { - static constexpr uint64_t multiplier01{ 1801439851ull }; - static constexpr uint64_t multiplier02{ 109951163ull }; - static constexpr uint64_t multiplier03{ 5243ull }; - uint64_t high{ value }; - multiply(high, multiplier01); - high = high >> 54; - const uint64_t low = value - high * 10000000ull; - uint64_t aa = (high * multiplier03) >> 19ull; - buf[0] = int_tables::charTable1[aa]; - std::memcpy(buf + 1ull, int_tables::charTable02 + high - aa * 100ull, 2ull); - const uint64_t aabb = (low * multiplier02) >> 40ull; + static constexpr uint64_t multiplier01{ 720575941ull }; + static constexpr uint64_t multiplier02{ 5243ull }; + const uint64_t high = (value * multiplier01) >> 56ull; + const uint64_t low = value - high * 100000000ull; + std::memcpy(buf, int_tables::charTable02 + high, 2ull); + static constexpr uint64_t multiplier03{ 109951163ull }; + const uint64_t aabb = (low * multiplier03) >> 40ull; const uint64_t ccdd = low - aabb * 10000ull; - aa = (aabb * multiplier03) >> 19ull; - const uint64_t cc = (ccdd * multiplier03) >> 19ull; - buf[3] = int_tables::charTable1[aa]; + const uint64_t aa = (aabb * multiplier02) >> 19ull; + const uint64_t cc = (ccdd * multiplier02) >> 19ull; + std::memcpy(buf + 2, int_tables::charTable02 + aa, 2ull); std::memcpy(buf + 4ull, int_tables::charTable02 + aabb - aa * 100ull, 2ull); std::memcpy(buf + 6ull, int_tables::charTable02 + cc, 2ull); std::memcpy(buf + 8ull, int_tables::charTable02 + ccdd - cc * 100ull, 2ull); diff --git a/Include/jsonifier/Utilities/TypeEntities.hpp b/Include/jsonifier/Utilities/TypeEntities.hpp index a006193dd..35c459e68 100644 --- a/Include/jsonifier/Utilities/TypeEntities.hpp +++ b/Include/jsonifier/Utilities/TypeEntities.hpp @@ -54,10 +54,6 @@ namespace jsonifier::internal { return os; } - static void printLocation(const std::source_location& location = std::source_location::current()) { - std::cout << location; - } - template class parser; template class vector;