AK: Inline *String::is_one_of<Ts...>()

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.
This commit is contained in:
Ali Mohammad Pur 2021-06-04 14:16:29 +04:30 committed by Andreas Kling
parent a446530c0d
commit 824a40e95b
Notes: sideshowbarker 2024-07-18 16:55:00 +09:00
3 changed files with 9 additions and 21 deletions

View file

@ -76,17 +76,13 @@ public:
static void did_destroy_impl(Badge<StringImpl>, StringImpl&);
template<typename T, typename... Rest>
bool is_one_of(const T& string, Rest... rest) const
template<typename... Ts>
[[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<Ts>(strings)));
}
private:
bool is_one_of() const { return false; }
RefPtr<StringImpl> m_impl;
};

View file

@ -282,17 +282,13 @@ public:
Vector<size_t> find_all(const String& needle) const;
[[nodiscard]] String reverse() const;
template<typename T, typename... Rest>
[[nodiscard]] bool is_one_of(const T& string, Rest... rest) const
template<typename... Ts>
[[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<Ts>(strings)));
}
private:
[[nodiscard]] bool is_one_of() const { return false; }
RefPtr<StringImpl> m_impl;
};

View file

@ -209,17 +209,13 @@ public:
[[nodiscard]] bool is_whitespace() const { return StringUtils::is_whitespace(*this); }
template<typename T, typename... Rest>
[[nodiscard]] bool is_one_of(const T& string, Rest... rest) const
template<typename... Ts>
[[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<Ts>(strings)));
}
private:
[[nodiscard]] bool is_one_of() const { return false; }
friend class String;
const char* m_characters { nullptr };
size_t m_length { 0 };