commit f35e04cdd4a90544b7842a84c24c0fba3df7dd46
parent 668785a82aa8479cf0d8212a66a9b656be17010b
Author: Sebastian <sebastian@sebsite.pw>
Date: Mon, 27 Nov 2023 01:18:08 -0500
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 <sebastian@sebsite.pw>
Diffstat:
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git 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
@@ -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
@@ -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