mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Mark the StringView user-defined literal as consteval
Even though the StringView(char*, size_t) constructor only runs its overflow check when evaluated in a runtime context, the code generated here could prevent the compiler from optimizing invocations from the StringView user-defined literal (verified on Compiler Explorer). This changes the user-defined literal declaration to be consteval to ensure it is evaluated at compile time.
This commit is contained in:
parent
3b037726e9
commit
31515a9147
Notes:
sideshowbarker
2024-07-17 21:16:31 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/31515a9147 Pull-request: https://github.com/SerenityOS/serenity/pull/13097 Reviewed-by: https://github.com/bgianfo ✅ Reviewed-by: https://github.com/ldm5180 ✅
1 changed files with 9 additions and 1 deletions
|
@ -301,7 +301,15 @@ struct CaseInsensitiveStringViewTraits : public Traits<StringView> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] ALWAYS_INLINE constexpr AK::StringView operator"" sv(const char* cstring, size_t length)
|
// FIXME: Remove this when clang fully supports consteval (specifically in the context of default parameter initialization).
|
||||||
|
// See: https://stackoverflow.com/questions/68789984/immediate-function-as-default-function-argument-initializer-in-clang
|
||||||
|
#if defined(__clang__)
|
||||||
|
# define AK_STRING_VIEW_LITERAL_CONSTEVAL constexpr
|
||||||
|
#else
|
||||||
|
# define AK_STRING_VIEW_LITERAL_CONSTEVAL consteval
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[[nodiscard]] ALWAYS_INLINE AK_STRING_VIEW_LITERAL_CONSTEVAL AK::StringView operator"" sv(const char* cstring, size_t length)
|
||||||
{
|
{
|
||||||
return AK::StringView(cstring, length);
|
return AK::StringView(cstring, length);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue