Skip to content

Commit ff0c467

Browse files
authored
Use std::equal instead of string_view == in begins_with. (#474)
This has a slightly better codgen - https://godbolt.org/z/z3onK91bT and supports [execution policy](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t) in case sequential comparisons are not sufficient.
1 parent 313e585 commit ff0c467

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: include/ada/checkers-inl.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "ada/common_defs.h"
99

10+
#include <algorithm>
1011
#include <string_view>
1112
#include <cstring>
1213

@@ -57,7 +58,7 @@ ada_really_inline constexpr bool begins_with(std::string_view view,
5758
std::string_view prefix) {
5859
// in C++20, you have view.begins_with(prefix)
5960
return view.size() >= prefix.size() &&
60-
(view.substr(0, prefix.size()) == prefix);
61+
std::equal(prefix.begin(), prefix.end(), view.begin());
6162
}
6263

6364
} // namespace ada::checkers

0 commit comments

Comments
 (0)