mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +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:
parent
a446530c0d
commit
824a40e95b
Notes:
sideshowbarker
2024-07-18 16:55:00 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/824a40e95bc Pull-request: https://github.com/SerenityOS/serenity/pull/7767
3 changed files with 9 additions and 21 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
10
AK/String.h
10
AK/String.h
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue