mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibWeb: Avoid allocating UTF-16 strings only the UTF-16 length is needed
This commit is contained in:
parent
7a17c654d2
commit
4a166a45ec
Notes:
github-actions[bot]
2024-07-31 09:56:31 +00:00
Author: https://github.com/trflynn89
Commit: 4a166a45ec
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/901
2 changed files with 4 additions and 6 deletions
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
|
#include <AK/Utf16View.h>
|
||||||
#include <LibUnicode/Forward.h>
|
#include <LibUnicode/Forward.h>
|
||||||
#include <LibWeb/DOM/ChildNode.h>
|
#include <LibWeb/DOM/ChildNode.h>
|
||||||
#include <LibWeb/DOM/Node.h>
|
#include <LibWeb/DOM/Node.h>
|
||||||
|
@ -30,9 +31,7 @@ public:
|
||||||
|
|
||||||
unsigned length_in_utf16_code_units() const
|
unsigned length_in_utf16_code_units() const
|
||||||
{
|
{
|
||||||
// FIXME: This is inefficient!
|
return AK::utf16_code_unit_length_from_utf8(m_data);
|
||||||
auto utf16_data = MUST(AK::utf8_to_utf16(m_data));
|
|
||||||
return Utf16View { utf16_data }.length_in_code_units();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<String> substring_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units) const;
|
WebIDL::ExceptionOr<String> substring_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units) const;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/Utf16View.h>
|
||||||
#include <LibWeb/Bindings/HTMLTextAreaElementPrototype.h>
|
#include <LibWeb/Bindings/HTMLTextAreaElementPrototype.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/CSS/StyleProperties.h>
|
#include <LibWeb/CSS/StyleProperties.h>
|
||||||
|
@ -189,9 +190,7 @@ String HTMLTextAreaElement::api_value() const
|
||||||
u32 HTMLTextAreaElement::text_length() const
|
u32 HTMLTextAreaElement::text_length() const
|
||||||
{
|
{
|
||||||
// The textLength IDL attribute must return the length of the element's API value.
|
// The textLength IDL attribute must return the length of the element's API value.
|
||||||
// FIXME: This is inefficient!
|
return AK::utf16_code_unit_length_from_utf8(api_value());
|
||||||
auto utf16_data = MUST(AK::utf8_to_utf16(api_value()));
|
|
||||||
return Utf16View { utf16_data }.length_in_code_units();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue