From 824a40e95bc246ee9999ff0066e57383721e70c6 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 4 Jun 2021 14:16:29 +0430 Subject: [PATCH] AK: Inline *String::is_one_of() Previously this was generating a crazy number of symbols, and it was also pretty-damn-slow as it was defined recursively, which made the compiler incapable of inlining it (due to the many many layers of recursion before it terminated). This commit replaces the recursion with a pack expansion and marks it always-inline. --- AK/FlyString.h | 10 +++------- AK/String.h | 10 +++------- AK/StringView.h | 10 +++------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/AK/FlyString.h b/AK/FlyString.h index 2db89366dfd..778d448b3d3 100644 --- a/AK/FlyString.h +++ b/AK/FlyString.h @@ -76,17 +76,13 @@ public: static void did_destroy_impl(Badge, StringImpl&); - template - bool is_one_of(const T& string, Rest... rest) const + template + [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts... strings) const { - if (*this == string) - return true; - return is_one_of(rest...); + return (... || this->operator==(forward(strings))); } private: - bool is_one_of() const { return false; } - RefPtr m_impl; }; diff --git a/AK/String.h b/AK/String.h index b1d453e60dc..6f9b98fdde7 100644 --- a/AK/String.h +++ b/AK/String.h @@ -282,17 +282,13 @@ public: Vector find_all(const String& needle) const; [[nodiscard]] String reverse() const; - template - [[nodiscard]] bool is_one_of(const T& string, Rest... rest) const + template + [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts... strings) const { - if (*this == string) - return true; - return is_one_of(rest...); + return (... || this->operator==(forward(strings))); } private: - [[nodiscard]] bool is_one_of() const { return false; } - RefPtr m_impl; }; diff --git a/AK/StringView.h b/AK/StringView.h index d7738f08ed7..78dfa8494da 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -209,17 +209,13 @@ public: [[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); } - template - [[nodiscard]] bool is_one_of(const T& string, Rest... rest) const + template + [[nodiscard]] ALWAYS_INLINE constexpr bool is_one_of(Ts... strings) const { - if (*this == string) - return true; - return is_one_of(rest...); + return (... || this->operator==(forward(strings))); } private: - [[nodiscard]] bool is_one_of() const { return false; } - friend class String; const char* m_characters { nullptr }; size_t m_length { 0 };