Skip to content

Commit

Permalink
Update StringUtils.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTimeChris committed Sep 20, 2024
1 parent 4ac4566 commit 3781b2b
Show file tree
Hide file tree
Showing 55 changed files with 174,306 additions and 158,470 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CLANG-Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
sudo apt update && sudo apt upgrade
wget https://apt.llvm.org/llvm.sh
chmod u+x llvm.sh
sudo ./llvm.sh 19
sudo ./llvm.sh 20
- name: Install Seaborn
run: |
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Configure CMake
working-directory: ./
run: |
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/bin/clang++-19 -DJSONIFIER_TEST="TRUE"
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/bin/clang++-20 -DJSONIFIER_TEST="TRUE"
- name: Build the Test
working-directory: ./Build
Expand Down
14 changes: 7 additions & 7 deletions Include/jsonifier/Allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

namespace jsonifier_internal {

template<auto multiple, typename value_type = decltype(multiple)> JSONIFIER_INLINE constexpr value_type roundUpToMultiple(value_type value) noexcept {
template<auto multiple, typename value_type = decltype(multiple)> JSONIFIER_ALWAYS_INLINE constexpr value_type roundUpToMultiple(value_type value) noexcept {
auto remainder = value % multiple;
return remainder == 0 ? value : value + (multiple - remainder);
}

template<auto multiple, typename value_type = decltype(multiple)> JSONIFIER_INLINE constexpr value_type roundDownToMultiple(value_type value) noexcept {
template<auto multiple, typename value_type = decltype(multiple)> JSONIFIER_ALWAYS_INLINE constexpr value_type roundDownToMultiple(value_type value) noexcept {
return static_cast<int64_t>(value) >= 0 ? (value / multiple) * multiple : ((value - multiple + 1) / multiple) * multiple;
}

Expand All @@ -44,7 +44,7 @@ namespace jsonifier_internal {
using size_type = size_t;
using allocator_traits = std::allocator_traits<alloc_wrapper<value_type>>;

JSONIFIER_INLINE pointer allocate(size_type count) noexcept {
JSONIFIER_ALWAYS_INLINE pointer allocate(size_type count) noexcept {
if (count == 0) [[unlikely]] {
return nullptr;
}
Expand All @@ -55,7 +55,7 @@ namespace jsonifier_internal {
#endif
}

JSONIFIER_INLINE void deallocate(pointer ptr, size_t newSize = 0) noexcept {
JSONIFIER_ALWAYS_INLINE void deallocate(pointer ptr, size_t newSize = 0) noexcept {
( void )newSize;
if (ptr) [[likely]] {
#if defined(JSONIFIER_MSVC)
Expand All @@ -66,15 +66,15 @@ namespace jsonifier_internal {
}
}

template<typename... arg_types> JSONIFIER_INLINE void construct(pointer ptr, arg_types&&... args) noexcept {
template<typename... arg_types> JSONIFIER_ALWAYS_INLINE void construct(pointer ptr, arg_types&&... args) noexcept {
new (ptr) value_type(std::forward<arg_types>(args)...);
}

JSONIFIER_INLINE static size_type maxSize() noexcept {
JSONIFIER_ALWAYS_INLINE static size_type maxSize() noexcept {
return allocator_traits::max_size(alloc_wrapper{});
}

JSONIFIER_INLINE void destroy(pointer ptr) noexcept {
JSONIFIER_ALWAYS_INLINE void destroy(pointer ptr) noexcept {
ptr->~value_type();
}
};
Expand Down
18 changes: 9 additions & 9 deletions Include/jsonifier/Compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@

namespace jsonifier_internal {

template<const uint8_t repeat, jsonifier::concepts::uint16_type return_type> JSONIFIER_INLINE constexpr return_type repeatByte() noexcept {
template<const uint8_t repeat, jsonifier::concepts::uint16_type return_type> JSONIFIER_ALWAYS_INLINE constexpr return_type repeatByte() noexcept {
return 0x0101ull * repeat;
}

template<const uint8_t repeat, jsonifier::concepts::uint32_type return_type> JSONIFIER_INLINE constexpr return_type repeatByte() noexcept {
template<const uint8_t repeat, jsonifier::concepts::uint32_type return_type> JSONIFIER_ALWAYS_INLINE constexpr return_type repeatByte() noexcept {
return 0x01010101ull * repeat;
}

template<const uint8_t repeat, jsonifier::concepts::uint64_type return_type> JSONIFIER_INLINE constexpr return_type repeatByte() noexcept {
template<const uint8_t repeat, jsonifier::concepts::uint64_type return_type> JSONIFIER_ALWAYS_INLINE constexpr return_type repeatByte() noexcept {
return 0x0101010101010101ull * repeat;
}

template<jsonifier::concepts::uint16_type integer_type> JSONIFIER_INLINE constexpr integer_type hasZero(const integer_type chunk) noexcept {
template<jsonifier::concepts::uint16_type integer_type> JSONIFIER_ALWAYS_INLINE constexpr integer_type hasZero(const integer_type chunk) noexcept {
return (((chunk - 0x0101u) & ~chunk) & 0x80808u);
}

template<jsonifier::concepts::uint32_type integer_type> JSONIFIER_INLINE constexpr integer_type hasZero(const integer_type chunk) noexcept {
template<jsonifier::concepts::uint32_type integer_type> JSONIFIER_ALWAYS_INLINE constexpr integer_type hasZero(const integer_type chunk) noexcept {
return (((chunk - 0x01010101u) & ~chunk) & 0x80808080u);
}

template<jsonifier::concepts::uint64_type integer_type> JSONIFIER_INLINE constexpr integer_type hasZero(const integer_type chunk) noexcept {
template<jsonifier::concepts::uint64_type integer_type> JSONIFIER_ALWAYS_INLINE constexpr integer_type hasZero(const integer_type chunk) noexcept {
return (((chunk - 0x0101010101010101u) & ~chunk) & 0x8080808080808080u);
}

template<char value> struct char_comparison {
JSONIFIER_INLINE static auto* memchar(auto* data, size_t lengthNew) noexcept {
JSONIFIER_ALWAYS_INLINE static auto* memchar(auto* data, size_t lengthNew) noexcept {
#if JSONIFIER_CHECK_FOR_AVX(JSONIFIER_AVX512)
if (lengthNew >= 64) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::type;
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace jsonifier_internal {
}
};

template<typename char_type01, typename char_type02> JSONIFIER_INLINE bool compare(char_type01* lhs, char_type02* rhs, size_t lengthNew) noexcept {
template<typename char_type01, typename char_type02> JSONIFIER_ALWAYS_INLINE bool compare(char_type01* lhs, char_type02* rhs, size_t lengthNew) noexcept {
#if JSONIFIER_CHECK_FOR_AVX(JSONIFIER_AVX512)
if (lengthNew >= 64) {
using simd_type = typename get_type_at_index<simd_internal::avx_list, 2>::type::type;
Expand Down Expand Up @@ -277,7 +277,7 @@ namespace jsonifier_internal {
}

template<size_t count, typename char_type01, typename char_type02> struct comparison {
JSONIFIER_INLINE static bool compare(const char_type01* lhs, const char_type02* rhs) noexcept {
JSONIFIER_ALWAYS_INLINE static bool compare(const char_type01* lhs, const char_type02* rhs) noexcept {
size_t lengthNew{ count };
#if JSONIFIER_CHECK_FOR_AVX(JSONIFIER_AVX512)
if constexpr (count >= 64) {
Expand Down
10 changes: 5 additions & 5 deletions Include/jsonifier/DToStr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ namespace jsonifier_internal {
34349738368, 38554705664, 38554705664, 38554705664, 41949672960, 41949672960, 41949672960, 42949672960, 42949672960 };

// https://lemire.me/blog/2021/06/03/computing-the-number-of-digits-of-an-integer-even-faster/
JSONIFIER_INLINE uint64_t fastDigitCount(const uint32_t x) noexcept {
JSONIFIER_ALWAYS_INLINE uint64_t fastDigitCount(const uint32_t x) noexcept {
return (x + digitCountTable[31 - simd_internal::lzcnt(x | 1)]) >> 32;
}

inline constexpr uint8_t decTrailingZeroTable[]{ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0 };

template<typename char_type> JSONIFIER_INLINE char_type* writeU64Len15To17Trim(char_type* buf, uint64_t sig) noexcept {
template<typename char_type> JSONIFIER_ALWAYS_INLINE char_type* writeU64Len15To17Trim(char_type* buf, uint64_t sig) noexcept {
uint32_t tz1, tz2, tz;

uint32_t abbccddee = uint32_t(sig / 100000000);
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace jsonifier_internal {
}
}

template<typename char_type> JSONIFIER_INLINE char_type* writeU32Len1To9(char_type* buf, uint32_t val) noexcept {
template<typename char_type> JSONIFIER_ALWAYS_INLINE char_type* writeU32Len1To9(char_type* buf, uint32_t val) noexcept {
if (val < 10) {
*buf = uint8_t(val + '0');
return buf + 1;
Expand Down Expand Up @@ -147,11 +147,11 @@ namespace jsonifier_internal {
return end;
}

JSONIFIER_INLINE consteval uint32_t numbits(uint32_t x) noexcept {
JSONIFIER_ALWAYS_INLINE consteval uint32_t numbits(uint32_t x) noexcept {
return x < 2 ? x : 1 + numbits(x >> 1);
}

template<jsonifier::concepts::float_type value_type, typename char_type> JSONIFIER_INLINE char_type* toChars(char_type* buf, value_type val) noexcept {
template<jsonifier::concepts::float_type value_type, typename char_type> JSONIFIER_ALWAYS_INLINE char_type* toChars(char_type* buf, value_type val) noexcept {
static_assert(std::numeric_limits<value_type>::is_iec559);
static_assert(std::numeric_limits<value_type>::radix == 2);
static_assert(std::is_same_v<float, value_type> || std::is_same_v<double, value_type>);
Expand Down
Loading

0 comments on commit 3781b2b

Please sign in to comment.