Skip to content

Commit

Permalink
Small changes (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig authored Nov 20, 2024
1 parent 418f36f commit c3cbb51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
14 changes: 0 additions & 14 deletions include/ada/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions include/ada/unicode-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c3cbb51

Please sign in to comment.