From e28a6d5da4176f8679b97f931d0988bd066ea95b Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Thu, 9 Mar 2023 17:45:33 +0100 Subject: [PATCH] AK: Add FlyString::from_deprecated_fly_string() Let's add FlyString::from_deprecated_fly_string() so we can use it instead of FlyString::from_utf8(). This will make it easier to detect potential unncessary allocations as we transfer to FlyString. --- AK/FlyString.cpp | 5 +++++ AK/FlyString.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AK/FlyString.cpp b/AK/FlyString.cpp index d745768ade9..9a29caf1db2 100644 --- a/AK/FlyString.cpp +++ b/AK/FlyString.cpp @@ -168,6 +168,11 @@ DeprecatedFlyString FlyString::to_deprecated_fly_string() const return DeprecatedFlyString(bytes_as_string_view()); } +ErrorOr FlyString::from_deprecated_fly_string(DeprecatedFlyString const& deprecated_fly_string) +{ + return FlyString::from_utf8(deprecated_fly_string.view()); +} + unsigned Traits::hash(FlyString const& fly_string) { return fly_string.hash(); diff --git a/AK/FlyString.h b/AK/FlyString.h index 5ca49836fe6..a2e68cef47d 100644 --- a/AK/FlyString.h +++ b/AK/FlyString.h @@ -51,8 +51,9 @@ public: // This is primarily interesting to unit tests. [[nodiscard]] static size_t number_of_fly_strings(); - // FIXME: Remove this once all code has been ported to FlyString + // FIXME: Remove these once all code has been ported to FlyString [[nodiscard]] DeprecatedFlyString to_deprecated_fly_string() const; + static ErrorOr from_deprecated_fly_string(DeprecatedFlyString const&); // Compare this FlyString against another string with ASCII caseless matching. [[nodiscard]] bool equals_ignoring_ascii_case(FlyString const&) const;