AK: Allow inlining more string functions

This commit is contained in:
Gunnar Beutner 2021-06-03 01:35:01 +02:00 committed by Andreas Kling
parent ed0068d04d
commit a4f320c76b
Notes: sideshowbarker 2024-07-18 16:58:40 +09:00
4 changed files with 17 additions and 24 deletions

View file

@ -73,11 +73,6 @@ FlyString::FlyString(StringView const& string)
}
}
FlyString::FlyString(const char* string)
: FlyString(static_cast<String>(string))
{
}
template<typename T>
Optional<T> FlyString::to_int() const
{

View file

@ -23,7 +23,10 @@ public:
}
FlyString(const String&);
FlyString(const StringView&);
FlyString(const char*);
FlyString(const char* string)
: FlyString(static_cast<String>(string))
{
}
FlyString& operator=(const FlyString& other)
{

View file

@ -15,11 +15,6 @@
namespace AK {
String::String(const StringView& view)
{
m_impl = StringImpl::create(view.characters_without_null_termination(), view.length());
}
bool String::operator==(const FlyString& fly_string) const
{
return *this == String(fly_string.impl());
@ -72,11 +67,6 @@ bool String::operator>(const String& other) const
return strcmp(characters(), other.characters()) > 0;
}
String String::empty()
{
return StringImpl::the_empty_stringimpl();
}
bool String::copy_characters_to_buffer(char* buffer, size_t buffer_size) const
{
// We must fit at least the NUL-terminator.
@ -456,11 +446,6 @@ bool String::operator==(const char* cstring) const
return !__builtin_strcmp(characters(), cstring);
}
StringView String::view() const
{
return { characters(), length() };
}
InputStream& operator>>(InputStream& stream, String& string)
{
StringBuilder builder;

View file

@ -42,7 +42,11 @@ public:
~String() = default;
String() = default;
String(const StringView&);
String(const StringView& view)
{
m_impl = StringImpl::create(view.characters_without_null_termination(), view.length());
}
String(const String& other)
: m_impl(const_cast<String&>(other).m_impl)
@ -203,7 +207,10 @@ public:
[[nodiscard]] String isolated_copy() const;
[[nodiscard]] static String empty();
[[nodiscard]] static String empty()
{
return StringImpl::the_empty_stringimpl();
}
[[nodiscard]] StringImpl* impl() { return m_impl.ptr(); }
[[nodiscard]] const StringImpl* impl() const { return m_impl.ptr(); }
@ -265,7 +272,10 @@ public:
return formatted("{}", value);
}
[[nodiscard]] StringView view() const;
[[nodiscard]] StringView view() const
{
return { characters(), length() };
}
int replace(const String& needle, const String& replacement, bool all_occurrences = false);
size_t count(const String& needle) const;