From d125a76f855e3d6b233b735a9508287548f2f04c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 13 Mar 2024 11:42:36 +0100 Subject: [PATCH] AK: Make FlyString-to-FlyString comparison inline & trivial This should never boil down to more than a machine word comparison. --- AK/FlyString.cpp | 5 ----- AK/FlyString.h | 2 +- AK/StringBase.h | 3 +++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/AK/FlyString.cpp b/AK/FlyString.cpp index d637289942..f4e3416508 100644 --- a/AK/FlyString.cpp +++ b/AK/FlyString.cpp @@ -89,11 +89,6 @@ StringView FlyString::bytes_as_string_view() const return m_data.bytes(); } -bool FlyString::operator==(FlyString const& other) const -{ - return m_data == other.m_data; -} - bool FlyString::operator==(String const& other) const { return m_data == other; diff --git a/AK/FlyString.h b/AK/FlyString.h index b0c9e18a05..6c8815a67f 100644 --- a/AK/FlyString.h +++ b/AK/FlyString.h @@ -41,7 +41,7 @@ public: [[nodiscard]] ReadonlyBytes bytes() const; [[nodiscard]] StringView bytes_as_string_view() const; - [[nodiscard]] bool operator==(FlyString const& other) const; + [[nodiscard]] ALWAYS_INLINE bool operator==(FlyString const& other) const { return m_data.raw({}) == other.m_data.raw({}); } [[nodiscard]] bool operator==(String const&) const; [[nodiscard]] bool operator==(StringView) const; [[nodiscard]] bool operator==(char const*) const; diff --git a/AK/StringBase.h b/AK/StringBase.h index dcfea0f639..cdad290360 100644 --- a/AK/StringBase.h +++ b/AK/StringBase.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -70,6 +71,8 @@ public: void did_create_fly_string(Badge) const; + [[nodiscard]] ALWAYS_INLINE FlatPtr raw(Badge) const { return bit_cast(m_data); } + protected: template ErrorOr replace_with_new_string(size_t byte_count, Func&& callback)