1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 08:28:11 +00:00

AK: Try to use StringViews more for substrings and splitting.

This commit is contained in:
Andreas Kling 2019-04-16 02:39:16 +02:00
parent a082738f04
commit 33920df299
9 changed files with 133 additions and 13 deletions

View file

@ -78,7 +78,10 @@ public:
}
Vector<String> split(char separator) const;
String substring(ssize_t start, ssize_t length) const;
String substring(int start, int length) const;
Vector<StringView> split_view(char separator) const;
StringView substring_view(int start, int length) const;
bool is_null() const { return !m_impl; }
bool is_empty() const { return length() == 0; }
@ -124,6 +127,19 @@ private:
RetainPtr<StringImpl> m_impl;
};
inline bool StringView::operator==(const String& string) const
{
if (string.is_null())
return !m_characters;
if (!m_characters)
return false;
if (m_length != string.length())
return false;
if (m_characters == string.characters())
return true;
return !memcmp(m_characters, string.characters(), m_length);
}
template<>
struct Traits<String> {
static unsigned hash(const String& s) { return s.impl() ? s.impl()->hash() : 0; }