mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:47:45 +00:00
LibJS+AK: Make String.prototype.repeat() way faster
Instead of using a StringBuilder, add a String::repeated(String, N) overload that takes advantage of knowing it's already all UTF-8. This makes the following microbenchmark go 4x faster: "foo".repeat(100_000_000) And for single character strings, we can even go 10x faster: "x".repeat(100_000_000)
This commit is contained in:
parent
9ce267944c
commit
a285e36041
3 changed files with 21 additions and 4 deletions
|
@ -92,6 +92,9 @@ public:
|
|||
// Creates a new String with a single code point repeated N times.
|
||||
static ErrorOr<String> repeated(u32 code_point, size_t count);
|
||||
|
||||
// Creates a new String from another string, repeated N times.
|
||||
static String repeated(String const&, size_t count);
|
||||
|
||||
// Creates a new String by case-transforming this String. Using these methods require linking LibUnicode into your application.
|
||||
ErrorOr<String> to_lowercase(Optional<StringView> const& locale = {}) const;
|
||||
ErrorOr<String> to_uppercase(Optional<StringView> const& locale = {}) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue