[Tarantool-patches] [PATCH v4 06/16] sql: introduce mem_append()
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Tue Oct 5 00:52:43 MSK 2021
Thanks for working on this!
> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 079083fa1..b8ead8f41 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -1925,6 +1925,27 @@ mem_move(struct Mem *to, struct Mem *from)
> from->zMalloc = NULL;
> }
>
> +int
> +mem_append(struct Mem *mem, const char *value, uint32_t len)
> +{
> + assert((mem->type & (MEM_TYPE_BIN | MEM_TYPE_STR)) != 0);
> + if (len == 0)
> + return 0;
> + int new_size = mem->n + len;
> + if (((mem->flags & (MEM_Static | MEM_Dyn | MEM_Ephem)) != 0) ||
> + mem->szMalloc < new_size) {
> + /*
> + * Force exponential buffer size growth to avoid having to call
> + * this routine too often.
> + */
> + if (sqlVdbeMemGrow(mem, new_size + mem->n, 1) != 0)
Looks like you could call sqlVdbeMemGrow() without all these checks
above. The grow function does them already.
> + return -1;
> + }
> + memcpy(&mem->z[mem->n], value, len);
> + mem->n = new_size;
> + return 0;
> +}
More information about the Tarantool-patches
mailing list