diff --git a/string.c b/string.c index a07b275..e9e68a1 100644 --- a/string.c +++ b/string.c @@ -262,14 +262,10 @@ fn u8 stringDeleteCodepointAtByte(String* s, u32 byte_offset) { if (s->length == 0) return 0; Codepoint cp = codepointFromBytes(s->bytes, byte_offset); - // shift all the bytes from the back towards the byte_offset - for (u32 i = 0; i < cp.size; i++) { - for (u32 ii = byte_offset+i; ii < s->length; ii++) { - s->bytes[ii] = s->bytes[ii+1]; - } - s->length -= 1; - } - s->bytes[byte_offset] = '\0'; + assert(cp.size + byte_offset <= s->length); + MemoryCopy(s->bytes + byte_offset, s->bytes + byte_offset + cp.size, s->length - byte_offset - cp.size); + s->length -= cp.size; + s->bytes[s->length] = '\0'; return cp.size; }