~sircmpwn/hare

f35e04cdd4a90544b7842a84c24c0fba3df7dd46 — Sebastian 3 months ago 668785a
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>
3 files changed, 3 insertions(+), 3 deletions(-)

M strings/iter.ha
M strings/runes.ha
M strings/trim.ha
M strings/iter.ha => strings/iter.ha +1 -1
@@ 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

M strings/runes.ha => strings/runes.ha +1 -1
@@ 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 = {

M strings/trim.ha => strings/trim.ha +1 -1
@@ 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