[Tarantool-patches] [PATCH v1 1/1] sql: clear MEM only if necessary
imeevma at tarantool.org
imeevma at tarantool.org
Wed Jul 21 18:11:36 MSK 2021
When mem_set _*() functions are executed, they are always cleared,
although this is not always necessary. After this patch, the MEM will
only be cleared if any flags are set for it.
Follow-up #5818
---
https://github.com/tarantool/tarantool/issues/5818
https://github.com/tarantool/tarantool/tree/imeevma/gh-5818-follow-up
src/box/sql/mem.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index fa80f6d5a..50063f490 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -223,7 +223,8 @@ mem_set_null(struct Mem *mem)
void
mem_set_int(struct Mem *mem, int64_t value, bool is_neg)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->u.i = value;
mem->type = is_neg ? MEM_TYPE_INT : MEM_TYPE_UINT;
assert(mem->flags == 0);
@@ -233,7 +234,8 @@ mem_set_int(struct Mem *mem, int64_t value, bool is_neg)
void
mem_set_uint(struct Mem *mem, uint64_t value)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->u.u = value;
mem->type = MEM_TYPE_UINT;
assert(mem->flags == 0);
@@ -243,7 +245,8 @@ mem_set_uint(struct Mem *mem, uint64_t value)
void
mem_set_bool(struct Mem *mem, bool value)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->u.b = value;
mem->type = MEM_TYPE_BOOL;
assert(mem->flags == 0);
@@ -253,7 +256,8 @@ mem_set_bool(struct Mem *mem, bool value)
void
mem_set_double(struct Mem *mem, double value)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->field_type = FIELD_TYPE_DOUBLE;
assert(mem->flags == 0);
if (sqlIsNaN(value))
@@ -265,7 +269,8 @@ mem_set_double(struct Mem *mem, double value)
void
mem_set_uuid(struct Mem *mem, const struct tt_uuid *uuid)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->field_type = FIELD_TYPE_UUID;
mem->u.uuid = *uuid;
mem->type = MEM_TYPE_UUID;
@@ -276,7 +281,8 @@ static inline void
set_str_const(struct Mem *mem, char *value, uint32_t len, int alloc_type)
{
assert((alloc_type & (MEM_Static | MEM_Ephem)) != 0);
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->z = value;
mem->n = len;
mem->type = MEM_TYPE_STR;
@@ -370,7 +376,8 @@ mem_copy_str(struct Mem *mem, const char *value, uint32_t len)
mem->field_type = FIELD_TYPE_STRING;
return 0;
}
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
if (sqlVdbeMemGrow(mem, len, 0) != 0)
return -1;
memcpy(mem->z, value, len);
@@ -396,7 +403,8 @@ static inline void
set_bin_const(struct Mem *mem, char *value, uint32_t size, int alloc_type)
{
assert((alloc_type & (MEM_Static | MEM_Ephem)) != 0);
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->z = value;
mem->n = size;
mem->type = MEM_TYPE_BIN;
@@ -462,7 +470,8 @@ mem_copy_bin(struct Mem *mem, const char *value, uint32_t size)
mem->field_type = FIELD_TYPE_VARBINARY;
return 0;
}
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
if (sqlVdbeMemGrow(mem, size, 0) != 0)
return -1;
memcpy(mem->z, value, size);
@@ -559,7 +568,8 @@ mem_set_array_allocated(struct Mem *mem, char *value, uint32_t size)
void
mem_set_invalid(struct Mem *mem)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->type = MEM_TYPE_INVALID;
assert(mem->flags == 0);
}
@@ -567,7 +577,8 @@ mem_set_invalid(struct Mem *mem)
void
mem_set_ptr(struct Mem *mem, void *ptr)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->type = MEM_TYPE_PTR;
assert(mem->flags == 0);
mem->u.p = ptr;
@@ -576,7 +587,8 @@ mem_set_ptr(struct Mem *mem, void *ptr)
void
mem_set_frame(struct Mem *mem, struct VdbeFrame *frame)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
mem->type = MEM_TYPE_FRAME;
assert(mem->flags == 0);
mem->u.pFrame = frame;
@@ -585,7 +597,8 @@ mem_set_frame(struct Mem *mem, struct VdbeFrame *frame)
int
mem_set_agg(struct Mem *mem, struct func *func, int size)
{
- mem_clear(mem);
+ if (mem->flags != 0)
+ mem_clear(mem);
if (size <= 0)
return 0;
if (sqlVdbeMemGrow(mem, size, 0) != 0)
@@ -1411,7 +1424,8 @@ mem_get_agg(const struct Mem *mem, void **accum)
int
mem_copy(struct Mem *to, const struct Mem *from)
{
- mem_clear(to);
+ if (to->flags != 0)
+ mem_clear(to);
to->u = from->u;
to->type = from->type;
to->flags = from->flags;
@@ -1438,7 +1452,8 @@ mem_copy(struct Mem *to, const struct Mem *from)
void
mem_copy_as_ephemeral(struct Mem *to, const struct Mem *from)
{
- mem_clear(to);
+ if (to->flags != 0)
+ mem_clear(to);
to->u = from->u;
to->type = from->type;
to->flags = from->flags;
--
2.25.1
More information about the Tarantool-patches
mailing list