1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:58:11 +00:00

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
3 changed files with 9 additions and 21 deletions

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;
};