Skip to content

Commit bfb5e77

Browse files
committed
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>
1 parent 5f59f39 commit bfb5e77

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

py/vstr.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,13 @@ char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) {
188188
if (byte_pos > l) {
189189
byte_pos = l;
190190
}
191-
if (byte_len > 0) {
192-
// ensure room for the new bytes
193-
vstr_ensure_extra(vstr, byte_len);
194-
// copy up the string to make room for the new bytes
195-
memmove(vstr->buf + byte_pos + byte_len, vstr->buf + byte_pos, l - byte_pos);
196-
// increase the length
197-
vstr->len += byte_len;
198-
}
191+
// ensure room for the new bytes
192+
vstr_ensure_extra(vstr, byte_len);
193+
// copy up the string to make room for the new bytes
194+
memmove(vstr->buf + byte_pos + byte_len, vstr->buf + byte_pos, l - byte_pos);
195+
// increase the length
196+
vstr->len += byte_len;
197+
// return a pointer to the location to insert new bytes at
199198
return vstr->buf + byte_pos;
200199
}
201200

0 commit comments

Comments
 (0)