From 268000e16641d4659a406b8a20eaf89bcddca1ac Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 1 Feb 2020 13:54:13 +0100 Subject: [PATCH] AK: Always inline StringView(const char*) Also use strlen() instead of manually walking the string. This allows GCC to optimize away the strlen() entirely for string literals. :^) --- AK/StringView.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/AK/StringView.h b/AK/StringView.h index e17373ca0c..6eab64ceec 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -47,13 +47,10 @@ public: , m_length(length) { } - StringView(const char* cstring) + [[gnu::always_inline]] inline StringView(const char* cstring) : m_characters(cstring) + , m_length(cstring ? strlen(cstring) : 0) { - if (cstring) { - while (*(cstring++)) - ++m_length; - } } StringView(const ByteBuffer&);