LibWeb: Avoid allocating UTF-16 strings only the UTF-16 length is needed

(cherry picked from commit 4a166a45ec9db910542893133f08cc7de4ec974f,
minorly amended to resolve #include conflict due to our LibLocale
and LibUnicode being separate -- we don't want
https://github.com/LadybirdBrowser/ladybird/pull/257)
This commit is contained in:
Timothy Flynn
2024-07-30 06:46:30 -04:00
committed by Nico Weber
parent 59040d9bb8
commit cb17194de8
2 changed files with 4 additions and 6 deletions

View File

@@ -6,6 +6,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Utf16View.h>
#include <LibWeb/Bindings/HTMLTextAreaElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/StyleProperties.h>
@@ -189,9 +190,7 @@ String HTMLTextAreaElement::api_value() const
u32 HTMLTextAreaElement::text_length() const
{
// The textLength IDL attribute must return the length of the element's API value.
// FIXME: This is inefficient!
auto utf16_data = MUST(AK::utf8_to_utf16(api_value()));
return Utf16View { utf16_data }.length_in_code_units();
return AK::utf16_code_unit_length_from_utf8(api_value());
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#dom-cva-checkvalidity