mirror of
https://github.com/micropython/micropython.git
synced 2026-02-13 06:30:19 +01:00
py/vstr: Don't check for byte_len>0 in vstr_ins_blank_bytes.
Having this check takes code size and execution time, and it's not necessary: all callers of this function pass a non-zero value for `byte_len` already. And even if `byte_len` was zero, the code would still perform correctly. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
15
py/vstr.c
15
py/vstr.c
@@ -188,14 +188,13 @@ char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) {
|
||||
if (byte_pos > l) {
|
||||
byte_pos = l;
|
||||
}
|
||||
if (byte_len > 0) {
|
||||
// ensure room for the new bytes
|
||||
vstr_ensure_extra(vstr, byte_len);
|
||||
// copy up the string to make room for the new bytes
|
||||
memmove(vstr->buf + byte_pos + byte_len, vstr->buf + byte_pos, l - byte_pos);
|
||||
// increase the length
|
||||
vstr->len += byte_len;
|
||||
}
|
||||
// ensure room for the new bytes
|
||||
vstr_ensure_extra(vstr, byte_len);
|
||||
// copy up the string to make room for the new bytes
|
||||
memmove(vstr->buf + byte_pos + byte_len, vstr->buf + byte_pos, l - byte_pos);
|
||||
// increase the length
|
||||
vstr->len += byte_len;
|
||||
// return a pointer to the location to insert new bytes at
|
||||
return vstr->buf + byte_pos;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user