Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v1 1/1] sql: clear MEM only if necessary
Date: Wed, 21 Jul 2021 18:11:36 +0300	[thread overview]
Message-ID: <6069191c12e57726159e04f986fd1cd757a943bb.1626880242.git.imeevma@gmail.com> (raw)

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


                 reply	other threads:[~2021-07-21 15:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6069191c12e57726159e04f986fd1cd757a943bb.1626880242.git.imeevma@gmail.com \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: clear MEM only if necessary' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox