mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-07 01:56:38 +00:00
LibRegex: Avoid slicing a RegexStringView in non-unicode Compare ops
Getting a single code point is much faster than slicing into the string.
This commit is contained in:
parent
11abca421a
commit
221c52c696
Notes:
sideshowbarker
2024-07-17 08:55:54 +09:00
Author: https://github.com/alimpfard
Commit: 221c52c696
Pull-request: https://github.com/SerenityOS/serenity/pull/20240
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/trflynn89
2 changed files with 43 additions and 8 deletions
|
@ -434,6 +434,29 @@ public:
|
|||
});
|
||||
}
|
||||
|
||||
u32 code_unit_at(size_t code_unit_index) const
|
||||
{
|
||||
if (unicode())
|
||||
return operator[](code_unit_index);
|
||||
|
||||
return m_view.visit(
|
||||
[&](StringView view) -> u32 {
|
||||
auto ch = view[code_unit_index];
|
||||
if constexpr (IsSigned<char>) {
|
||||
if (ch < 0)
|
||||
return 256u + ch;
|
||||
return ch;
|
||||
}
|
||||
},
|
||||
[&](Utf32View const& view) -> u32 { return view[code_unit_index]; },
|
||||
[&](Utf16View const& view) -> u32 { return view.code_unit_at(code_unit_index); },
|
||||
[&](Utf8View const& view) -> u32 {
|
||||
auto it = view.iterator_at_byte_offset(code_unit_index);
|
||||
VERIFY(it != view.end());
|
||||
return *it;
|
||||
});
|
||||
}
|
||||
|
||||
size_t code_unit_offset_of(size_t code_point_index) const
|
||||
{
|
||||
return m_view.visit(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue