mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
AK: Remove endianness override from Utf16View
Utf16View is now always in "host" endian mode. This makes it smaller and less branchy for everyone!
This commit is contained in:
parent
0e9480b944
commit
7628ddfaf7
Notes:
github-actions[bot]
2025-04-16 08:06:00 +00:00
Author: https://github.com/awesomekling
Commit: 7628ddfaf7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4370
5 changed files with 16 additions and 159 deletions
|
@ -51,16 +51,14 @@ public:
|
|||
size_t length_in_code_units() const;
|
||||
|
||||
private:
|
||||
Utf16CodePointIterator(u16 const* ptr, size_t length, Endianness endianness)
|
||||
Utf16CodePointIterator(u16 const* ptr, size_t length)
|
||||
: m_ptr(ptr)
|
||||
, m_remaining_code_units(length)
|
||||
, m_endianness(endianness)
|
||||
{
|
||||
}
|
||||
|
||||
u16 const* m_ptr { nullptr };
|
||||
size_t m_remaining_code_units { 0 };
|
||||
Endianness m_endianness { Endianness::Host };
|
||||
};
|
||||
|
||||
class Utf16View {
|
||||
|
@ -74,18 +72,16 @@ public:
|
|||
Utf16View() = default;
|
||||
~Utf16View() = default;
|
||||
|
||||
explicit Utf16View(ReadonlySpan<u16> code_units, Endianness endianness = Endianness::Host)
|
||||
explicit Utf16View(ReadonlySpan<u16> code_units)
|
||||
: m_code_units(code_units)
|
||||
, m_endianness(endianness)
|
||||
{
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
Utf16View(char16_t const (&code_units)[Size], Endianness endianness = Endianness::Host)
|
||||
Utf16View(char16_t const (&code_units)[Size])
|
||||
: m_code_units(
|
||||
reinterpret_cast<u16 const*>(&code_units[0]),
|
||||
code_units[Size - 1] == u'\0' ? Size - 1 : Size)
|
||||
, m_endianness(endianness)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -104,10 +100,8 @@ public:
|
|||
size_t length_in_code_units() const { return m_code_units.size(); }
|
||||
size_t length_in_code_points() const;
|
||||
|
||||
Endianness endianness() const { return m_endianness; }
|
||||
|
||||
Utf16CodePointIterator begin() const { return { begin_ptr(), m_code_units.size(), m_endianness }; }
|
||||
Utf16CodePointIterator end() const { return { end_ptr(), 0, m_endianness }; }
|
||||
Utf16CodePointIterator begin() const { return { begin_ptr(), m_code_units.size() }; }
|
||||
Utf16CodePointIterator end() const { return { end_ptr(), 0 }; }
|
||||
|
||||
u16 const* data() const { return m_code_units.data(); }
|
||||
char16_t const* char_data() const { return reinterpret_cast<char16_t const*>(data()); }
|
||||
|
@ -142,7 +136,6 @@ private:
|
|||
|
||||
ReadonlySpan<u16> m_code_units;
|
||||
NO_UNIQUE_ADDRESS mutable Optional<size_t> m_length_in_code_points;
|
||||
Endianness m_endianness { Endianness::Host };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue