Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small changes #780

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not opposed to this change, @anonrig, but did you determine that it was worth doing? This seems significantly more complicated than what we had. It is fine if it is worth it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not noticable due to the complexity of Ada, but the instruction count should have been lower with the new implementation. Do you see different/worse results?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I am not going to check. I expect that it will save instructions especially on long inputs (say a 2x saving) and hopefully make things a bit faster.

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
Loading