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

perf: improve has_tabs_or_newline performance #670

Merged
merged 1 commit into from
Jul 6, 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
3 changes: 1 addition & 2 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ if(RUST_FOUND)

# Check if servo-url target was created successfully
if(TARGET servo-url)
message(STATUS "servo-url target was created. Linking benchmarks and servo-url.")
target_link_libraries(bench PRIVATE servo-url)
target_compile_definitions(bench PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")

Expand All @@ -287,8 +288,6 @@ if(RUST_FOUND)

target_link_libraries(wpt_bench PRIVATE servo-url)
target_compile_definitions(wpt_bench PRIVATE ADA_RUST_VERSION="${Rust_VERSION}")
else()
message(WARNING "servo-url target was not created. Skipping linking benchmarks and servo-url.")
endif()
else()
message(STATUS "Rust/Cargo is unavailable." )
Expand Down
22 changes: 8 additions & 14 deletions src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ADA_POP_DISABLE_WARNINGS

namespace ada::unicode {

constexpr bool is_tabs_or_newline(char c) noexcept {
return c == '\r' || c == '\n' || c == '\t';
}

constexpr uint64_t broadcast(uint8_t v) noexcept {
return 0x101010101010101ull * v;
}
Expand Down Expand Up @@ -50,13 +54,8 @@ ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
// first check for short strings in which case we do it naively.
if (user_input.size() < 16) { // slow path
for (size_t i = 0; i < user_input.size(); i++) {
if (user_input[i] == '\r' || user_input[i] == '\n' ||
user_input[i] == '\t') {
return true;
}
}
return false;
return std::any_of(user_input.begin(), user_input.end(),
is_tabs_or_newline);
}
// fast path for long strings (expected to be common)
size_t i = 0;
Expand Down Expand Up @@ -94,13 +93,8 @@ ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
// first check for short strings in which case we do it naively.
if (user_input.size() < 16) { // slow path
for (size_t i = 0; i < user_input.size(); i++) {
if (user_input[i] == '\r' || user_input[i] == '\n' ||
user_input[i] == '\t') {
return true;
}
}
return false;
return std::any_of(user_input.begin(), user_input.end(),
is_tabs_or_newline);
}
// fast path for long strings (expected to be common)
size_t i = 0;
Expand Down
Loading