From 06640edb63c67b3f602edb3e1b28eb9087754c9e Mon Sep 17 00:00:00 2001 From: Norbert Hajagos Date: Mon, 20 Jan 2025 10:50:29 +0100 Subject: [PATCH] Use parens, not WSA in tests, add docs linebreaks, factor calls into a var. --- crates/compiler/builtins/bitcode/src/str.zig | 5 +++-- crates/compiler/builtins/roc/Str.roc | 19 +++++++++++++++---- crates/compiler/test_gen/src/gen_str.rs | 6 +++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/crates/compiler/builtins/bitcode/src/str.zig b/crates/compiler/builtins/bitcode/src/str.zig index 73d57801ab..29bca5ca4c 100644 --- a/crates/compiler/builtins/bitcode/src/str.zig +++ b/crates/compiler/builtins/bitcode/src/str.zig @@ -371,11 +371,12 @@ pub const RocStr = extern struct { } fn refcount(self: RocStr) usize { - if ((self.getCapacity() == 0 and !self.isSeamlessSlice()) or self.isSmallStr()) { + const is_seamless_slice = self.isSeamlessSlice(); + if ((self.getCapacity() == 0 and !is_seamless_slice) or self.isSmallStr()) { return 1; } - const data_ptr = if (self.isSeamlessSlice()) + const data_ptr = if (is_seamless_slice) self.getAllocationPtr() else self.bytes; diff --git a/crates/compiler/builtins/roc/Str.roc b/crates/compiler/builtins/roc/Str.roc index 0391ec5352..5854c4428a 100644 --- a/crates/compiler/builtins/roc/Str.roc +++ b/crates/compiler/builtins/roc/Str.roc @@ -1094,17 +1094,28 @@ drop_suffix = |haystack, suffix| else haystack -## Returns a version of the string with all [ASCII characters](https://en.wikipedia.org/wiki/ASCII) lowercased. Non-ASCII characters are left unmodified. For example: +## Returns a version of the string with all [ASCII characters](https://en.wikipedia.org/wiki/ASCII) lowercased. +## Non-ASCII characters are left unmodified. For example: ## ## ```roc ## expect "CAFÉ".with_ascii_lowercased() == "cafÉ" ## ``` ## -## This function is useful for things like [command-line options](https://en.wikipedia.org/wiki/Command-line_interface#Command-line_option) and [environment variables](https://en.wikipedia.org/wiki/Environment_variablewhere you ## know in advance that you're dealing with a hardcoded string containing only ASCII characters. It has better performance than lowercasing operations which take Unicode into account. +## This function is useful for things like [command-line options](https://en.wikipedia.org/wiki/Command-line_interface#Command-line_option) +## and [environment variables](https://en.wikipedia.org/wiki/Environment_variable) +## know in advance that you're dealing with a hardcoded string containing only ASCII characters. +## It has better performance than lowercasing operations which take Unicode into account. ## -## That said, strings received from user input can always contain non-ASCII Unicode characters, and lowercasing [Unicode](https://unicode.org) works differently in different languages. For example, the string `"I"lowercases to `"i"## ` in English and to `"ı"` (a [dotless i](https://en.wikipedia.org/wiki/Dotless_I)) in Turkish. These rules can also change in each [Unicode release](https://www.unicode.org/releases/), so we have separate [`unicode` package]## (https://github.com/roc-lang/unicode) for Unicode capitalization that can be upgraded independently from the language's builtins. +## That said, strings received from user input can always contain +## non-ASCII Unicode characters, and lowercasing [Unicode](https://unicode.org) works +## differently in different languages. For example, the string `"I"` lowercases to `"i"` +## in English and to `"ı"` (a [dotless i](https://en.wikipedia.org/wiki/Dotless_I)) +## in Turkish. These rules can also change in each [Unicode release](https://www.unicode.org/releases/), +## so we have separate [`unicode` package](https://github.com/roc-lang/unicode) +## for Unicode capitalization that can be upgraded independently from the language's builtins. ## -## To do a case-insensitive comparison of the ASCII characters in a string, use [`caseless_ascii_equals`](#caseless_ascii_equals). +## To do a case-insensitive comparison of the ASCII characters in a string, +## use [`caseless_ascii_equals`](#caseless_ascii_equals). with_ascii_lowercased : Str -> Str expect Str.with_ascii_lowercased("cOFFÉ") == "coffÉ" diff --git a/crates/compiler/test_gen/src/gen_str.rs b/crates/compiler/test_gen/src/gen_str.rs index d28522bc63..f0d0df682a 100644 --- a/crates/compiler/test_gen/src/gen_str.rs +++ b/crates/compiler/test_gen/src/gen_str.rs @@ -2066,7 +2066,7 @@ fn str_drop_suffix() { fn with_ascii_lowercased() { assert_evals_to!( r#" - Str.with_ascii_lowercased "cOFFÉ" + Str.with_ascii_lowercased("cOFFÉ") "#, RocStr::from("coffÉ"), RocStr @@ -2079,8 +2079,8 @@ fn with_ascii_lowercased_non_zero_refcount() { assert_evals_to!( r#" original = "cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ cOFFÉ" - res = Str.with_ascii_lowercased original - Str.drop_prefix res original + res = Str.with_ascii_lowercased(original) + Str.drop_prefix(res, original) "#, RocStr::from("coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ coffÉ"), RocStr