mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:07:36 +00:00
AK: Inline all the trivial Utf8View functions
This improves parsing time on a large chunk of JS by ~3%.
This commit is contained in:
parent
1be4cbd639
commit
391352c112
2 changed files with 15 additions and 52 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue