LibJS: Skip redundant UTF-8 validation in rope string resolution

When resolving a rope, we've already taken care to resolve it to
a UTF-8 byte stream. There's no need to do a separate pass just for
validating the data again.

This was noticeable in some profiles. I made a simple microbenchmark
that gets a 30% speed-up:

    ("x" + "y".repeat(100_000_000)).trimStart()
This commit is contained in:
Andreas Kling 2023-12-29 16:17:51 +01:00
parent 3c039903fb
commit 0ad4be3d78
Notes: sideshowbarker 2024-07-17 02:29:45 +09:00

View File

@ -348,7 +348,8 @@ void PrimitiveString::resolve_rope_if_needed(EncodingPreference preference) cons
previous = current;
}
m_utf8_string = MUST(builder.to_string());
// NOTE: We've already produced valid UTF-8 above, so there's no need for additional validation.
m_utf8_string = builder.to_string_without_validation();
m_is_rope = false;
m_lhs = nullptr;
m_rhs = nullptr;