diff options
author | Louis Pilfold <louis@lpil.uk> | 2023-10-03 20:42:28 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-10-03 20:42:28 +0100 |
commit | d0d942ba9fda93a9338483335628fdae82a6fbad (patch) | |
tree | e157c69d149795ada0e2c4cf63fa06a16cf52ef2 | |
parent | 6ff91d92ac2a466c975c4db378740def2d2a55c6 (diff) | |
download | gleam_stdlib-d0d942ba9fda93a9338483335628fdae82a6fbad.tar.gz gleam_stdlib-d0d942ba9fda93a9338483335628fdae82a6fbad.zip |
Improve pop_grapheme perf on JS
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/gleam/string.gleam | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2422e7e..d553c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Improved performance of `string.to_graphemes` on JavaScript. - The `iterator` module gains the `map2` function. - The `list` module gains the `key_filter` function. diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 39a69d3..5a85cc3 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -679,6 +679,10 @@ fn do_trim_right(string string: String) -> String /// Splits a non-empty `String` into its first element (head) and rest (tail). /// This lets you pattern match on `String`s exactly as you would with lists. /// +/// Note on JavaScript using the function to iterate over a string will likely +/// be slower than using `to_graphemes` due to string slicing being more +/// expensive on JavaScript than Erlang. +/// /// ## Examples /// /// ```gleam @@ -707,6 +711,7 @@ fn do_pop_grapheme(string string: String) -> Result(#(String, String), Nil) /// ["a", "b", "c"] /// ``` /// +@external(javascript, "../gleam_stdlib.mjs", "graphemes") pub fn to_graphemes(string: String) -> List(String) { do_to_graphemes(string, []) |> list.reverse |