Skip to content

Commit

Permalink
AK: Make FlyString-to-FlyString comparison inline & trivial
Browse files Browse the repository at this point in the history
This should never boil down to more than a machine word comparison.
  • Loading branch information
awesomekling committed Mar 14, 2024
1 parent bc23c5b commit d125a76
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
5 changes: 0 additions & 5 deletions AK/FlyString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion AK/FlyString.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FlyString {
[[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;
Expand Down
3 changes: 3 additions & 0 deletions AK/StringBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include <AK/Badge.h>
#include <AK/Endian.h>
#include <AK/Forward.h>

Expand Down Expand Up @@ -70,6 +71,8 @@ class StringBase {

void did_create_fly_string(Badge<FlyString>) const;

[[nodiscard]] ALWAYS_INLINE FlatPtr raw(Badge<FlyString>) const { return bit_cast<FlatPtr>(m_data); }

protected:
template<typename Func>
ErrorOr<void> replace_with_new_string(size_t byte_count, Func&& callback)
Expand Down

0 comments on commit d125a76

Please sign in to comment.