summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-18 18:19:21 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-18 19:54:24 +0200
commit391352c1121e1709385d8dc47ab81980f24c5a6b (patch)
tree99eb8d66637de5e78d5252c97a85ab7594c9ccd8 /AK
parent1be4cbd6395202183d7aa74119661aae71a8b8d9 (diff)
downloadserenity-391352c1121e1709385d8dc47ab81980f24c5a6b.zip
AK: Inline all the trivial Utf8View functions
This improves parsing time on a large chunk of JS by ~3%.
Diffstat (limited to 'AK')
-rw-r--r--AK/Utf8View.cpp42
-rw-r--r--AK/Utf8View.h25
2 files changed, 15 insertions, 52 deletions
diff --git a/AK/Utf8View.cpp b/AK/Utf8View.cpp
index 8e4fdc23e0..4c559a886d 100644
--- a/AK/Utf8View.cpp
+++ b/AK/Utf8View.cpp
@@ -11,26 +11,6 @@
namespace AK {
-const unsigned char* Utf8View::begin_ptr() const
-{
- return (const unsigned char*)m_string.characters_without_null_termination();
-}
-
-const unsigned char* Utf8View::end_ptr() const
-{
- return begin_ptr() + m_string.length();
-}
-
-Utf8CodePointIterator Utf8View::begin() const
-{
- return { begin_ptr(), m_string.length() };
-}
-
-Utf8CodePointIterator Utf8View::end() const
-{
- return { end_ptr(), 0 };
-}
-
Utf8CodePointIterator Utf8View::iterator_at_byte_offset(size_t byte_offset) const
{
size_t current_offset = 0;
@@ -65,12 +45,6 @@ size_t Utf8View::byte_offset_of(size_t code_point_offset) const
return byte_offset;
}
-Utf8View Utf8View::substring_view(size_t byte_offset, size_t byte_length) const
-{
- StringView string = m_string.substring_view(byte_offset, byte_length);
- return Utf8View { string };
-}
-
Utf8View Utf8View::unicode_substring_view(size_t code_point_offset, size_t code_point_length) const
{
if (code_point_length == 0)
@@ -214,22 +188,6 @@ Utf8View Utf8View::trim(const Utf8View& characters, TrimMode mode) const
return substring_view(substring_start, substring_length);
}
-Utf8CodePointIterator::Utf8CodePointIterator(const unsigned char* ptr, size_t length)
- : m_ptr(ptr)
- , m_length(length)
-{
-}
-
-bool Utf8CodePointIterator::operator==(const Utf8CodePointIterator& other) const
-{
- return m_ptr == other.m_ptr && m_length == other.m_length;
-}
-
-bool Utf8CodePointIterator::operator!=(const Utf8CodePointIterator& other) const
-{
- return !(*this == other);
-}
-
Utf8CodePointIterator& Utf8CodePointIterator::operator++()
{
VERIFY(m_length > 0);
diff --git a/AK/Utf8View.h b/AK/Utf8View.h
index 5c63c79708..18b5a3df4b 100644
--- a/AK/Utf8View.h
+++ b/AK/Utf8View.h
@@ -22,8 +22,8 @@ public:
Utf8CodePointIterator() = default;
~Utf8CodePointIterator() = default;
- bool operator==(const Utf8CodePointIterator&) const;
- bool operator!=(const Utf8CodePointIterator&) const;
+ bool operator==(Utf8CodePointIterator const&) const = default;
+ bool operator!=(Utf8CodePointIterator const&) const = default;
Utf8CodePointIterator& operator++();
u32 operator*() const;
// NOTE: This returns {} if the peek is at or past EOF.
@@ -44,9 +44,14 @@ public:
bool done() const { return m_length == 0; }
private:
- Utf8CodePointIterator(const unsigned char*, size_t);
- const unsigned char* m_ptr { nullptr };
- size_t m_length;
+ Utf8CodePointIterator(u8 const* ptr, size_t length)
+ : m_ptr(ptr)
+ , m_length(length)
+ {
+ }
+
+ u8 const* m_ptr { nullptr };
+ size_t m_length { 0 };
};
class Utf8View {
@@ -71,8 +76,8 @@ public:
const StringView& as_string() const { return m_string; }
- Utf8CodePointIterator begin() const;
- Utf8CodePointIterator end() const;
+ Utf8CodePointIterator begin() const { return { begin_ptr(), m_string.length() }; }
+ Utf8CodePointIterator end() const { return { end_ptr(), 0 }; }
Utf8CodePointIterator iterator_at_byte_offset(size_t) const;
const unsigned char* bytes() const { return begin_ptr(); }
@@ -80,7 +85,7 @@ public:
size_t byte_offset_of(const Utf8CodePointIterator&) const;
size_t byte_offset_of(size_t code_point_offset) const;
- Utf8View substring_view(size_t byte_offset, size_t byte_length) const;
+ Utf8View substring_view(size_t byte_offset, size_t byte_length) const { return Utf8View { m_string.substring_view(byte_offset, byte_length) }; }
Utf8View substring_view(size_t byte_offset) const { return substring_view(byte_offset, byte_length() - byte_offset); }
Utf8View unicode_substring_view(size_t code_point_offset, size_t code_point_length) const;
Utf8View unicode_substring_view(size_t code_point_offset) const { return unicode_substring_view(code_point_offset, length() - code_point_offset); }
@@ -114,8 +119,8 @@ public:
}
private:
- const unsigned char* begin_ptr() const;
- const unsigned char* end_ptr() const;
+ u8 const* begin_ptr() const { return (u8 const*)m_string.characters_without_null_termination(); }
+ u8 const* end_ptr() const { return begin_ptr() + m_string.length(); }
size_t calculate_length() const;
StringView m_string;