From f35e04cdd4a90544b7842a84c24c0fba3df7dd46 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 27 Nov 2023 01:18:08 -0500 Subject: [PATCH] strings: consistently use fromutf8_unsafe strings used to use the unsafe variant in some places, and the safe variant in other places, with no pattern as to which is used where. I've changed all fromutf8 calls to fromutf8_unsafe calls, so calls to strings:: functions don't repeatedly iterate through the string to check that it's valid UTF-8 when it's already been proven that it is. Signed-off-by: Sebastian --- strings/iter.ha | 2 +- strings/runes.ha | 2 +- strings/trim.ha | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/strings/iter.ha b/strings/iter.ha index 5876241d..6e621a88 100644 --- a/strings/iter.ha +++ b/strings/iter.ha @@ -63,7 +63,7 @@ fn move(forward: bool, iter: *iterator) (rune | void) = { // Return a substring from the next rune to the end of the string. export fn iterstr(iter: *iterator) str = { - return fromutf8(iter.dec.src[iter.dec.offs..])!; + return fromutf8_unsafe(iter.dec.src[iter.dec.offs..])!; }; // Return a substring from the position of the first iterator to the position of diff --git a/strings/runes.ha b/strings/runes.ha index 840f40f1..c138c5c0 100644 --- a/strings/runes.ha +++ b/strings/runes.ha @@ -25,7 +25,7 @@ export fn fromrunes(rs: []rune) str = { const bs = utf8::encoderune(rs[i]); append(bytes, bs...); }; - return fromutf8(bytes)!; + return fromutf8_unsafe(bytes); }; @test fn fromrunes() void = { diff --git a/strings/trim.ha b/strings/trim.ha index 610877fc..3380b0cf 100644 --- a/strings/trim.ha +++ b/strings/trim.ha @@ -34,7 +34,7 @@ export fn ltrim(input: str, trim: rune...) str = { break; }; }; - return fromutf8(it.dec.src[it.dec.offs..])!; + return fromutf8_unsafe(it.dec.src[it.dec.offs..]); }; // Returns a string (borrowed from given input string) after trimming off of -- 2.45.2