lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

Replace `String.fromUtf8Unchecked` with `String.fromUtf8?`

Open Kha opened this issue 3 years ago • 3 comments

Unlike String.fromUtf8Unchecked, this one should check for valid UTF-8. In fact, since we have to decode the string anyway to figure out its character length, we might as well remove the former function.

Kha avatar Aug 12 '22 07:08 Kha

However all String.Pos-based functions immediately work for an Utf8Unchecked without any extra decoding because the UTF8 size is just the ByteArray size and can be cached from the start.

Vtec234 avatar Aug 12 '22 08:08 Vtec234

I'm not quite sure what you mean. String eagerly, always caches the number of code points.

Kha avatar Aug 12 '22 08:08 Kha

My bad, indeed there is an eager utf8_strlen call in the constructor and the "unchecked" is not any faster.

Vtec234 avatar Aug 12 '22 08:08 Vtec234