Преглед изворни кода

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()
Andreas Kling пре 1 година
родитељ
комит
0ad4be3d78
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp

+ 2 - 1
Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp

@@ -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;