diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-11 01:02:24 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-11 20:36:43 +0300 |
commit | 6d2b003b6e652e807a1021151cccf41a396f18b7 (patch) | |
tree | 48d69186d22d4b7a33beb69fc747ca23b95cfe0f /AK/StringView.h | |
parent | 4e40eaf34c578c438a2860dbe62e3a29334b4603 (diff) | |
download | serenity-6d2b003b6e652e807a1021151cccf41a396f18b7.zip |
AK: Make String::count not use strstr and take a StringView
This was needlessly copying StringView arguments, and was also using
strstr internally, which meant it was doing a bunch of unnecessary
strlen calls on it. This also moves the implementation to StringUtils
to allow API consistency between String and StringView.
Diffstat (limited to 'AK/StringView.h')
-rw-r--r-- | AK/StringView.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/AK/StringView.h b/AK/StringView.h index ba87d2c0c1..f6868d1b8a 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -220,6 +220,8 @@ public: [[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); } + [[nodiscard]] size_t count(StringView const& needle) const { return StringUtils::count(*this, needle); } + template<typename... Ts> [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts&&... strings) const { |