From c3cbb51c6b0baf2e4dfcf9bcba997127cf78f8a9 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Wed, 20 Nov 2024 18:57:00 -0500 Subject: [PATCH] Small changes (#780) --- include/ada/common_defs.h | 14 -------------- include/ada/unicode-inl.h | 29 +++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/ada/common_defs.h b/include/ada/common_defs.h index 35f86d3b1..cbac9029a 100644 --- a/include/ada/common_defs.h +++ b/include/ada/common_defs.h @@ -49,13 +49,6 @@ #define ada_unused #define ada_warn_unused -#ifndef ada_likely -#define ada_likely(x) x -#endif -#ifndef ada_unlikely -#define ada_unlikely(x) x -#endif - #define ADA_PUSH_DISABLE_WARNINGS __pragma(warning(push)) #define ADA_PUSH_DISABLE_ALL_WARNINGS __pragma(warning(push, 0)) #define ADA_DISABLE_VS_WARNING(WARNING_NUMBER) \ @@ -87,13 +80,6 @@ #define ada_unused __attribute__((unused)) #define ada_warn_unused __attribute__((warn_unused_result)) -#ifndef ada_likely -#define ada_likely(x) __builtin_expect(!!(x), 1) -#endif -#ifndef ada_unlikely -#define ada_unlikely(x) __builtin_expect(!!(x), 0) -#endif - #define ADA_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push") // gcc doesn't seem to disable all warnings with all and extra, add warnings // here as necessary diff --git a/include/ada/unicode-inl.h b/include/ada/unicode-inl.h index 772af6cf9..1809311f2 100644 --- a/include/ada/unicode-inl.h +++ b/include/ada/unicode-inl.h @@ -18,10 +18,31 @@ namespace ada::unicode { ada_really_inline size_t percent_encode_index(const std::string_view input, const uint8_t character_set[]) { - return std::distance( - input.begin(), std::ranges::find_if(input, [character_set](const char c) { - return character_sets::bit_at(character_set, c); - })); + const char* data = input.data(); + const size_t size = input.size(); + + // Process 8 bytes at a time using unrolled loop + size_t i = 0; + for (; i + 8 <= size; i += 8) { + unsigned char chunk[8]; + std::memcpy(&chunk, data + i, 8); // entices compiler to unconditionally process 8 characters + + // Check 8 characters at once + for (size_t j = 0; j < 8; j++) { + if (character_sets::bit_at(character_set, chunk[j])) { + return i + j; + } + } + } + + // Handle remaining bytes + for (; i < size; i++) { + if (character_sets::bit_at(character_set, data[i])) { + return i; + } + } + + return size; } } // namespace ada::unicode