faster and safer dbuf functions (#443)

This commit is contained in:
Fabrice Bellard
2025-10-13 13:51:25 +02:00
parent 2a53de04c6
commit 0d4cd2d051
5 changed files with 77 additions and 35 deletions

View File

@@ -117,7 +117,7 @@ static inline int is_digit(int c) {
/* insert 'len' bytes at position 'pos'. Return < 0 if error. */
static int dbuf_insert(DynBuf *s, int pos, int len)
{
if (dbuf_realloc(s, s->size + len))
if (dbuf_claim(s, len))
return -1;
memmove(s->buf + pos + len, s->buf + pos, s->size - pos);
s->size += len;
@@ -2340,7 +2340,7 @@ static int re_parse_alternative(REParseState *s, BOOL is_backward_dir)
speed is not really critical here) */
end = s->byte_code.size;
term_size = end - term_start;
if (dbuf_realloc(&s->byte_code, end + term_size))
if (dbuf_claim(&s->byte_code, term_size))
return -1;
memmove(s->byte_code.buf + start + term_size,
s->byte_code.buf + start,