From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A89AD6EC55; Wed, 21 Jul 2021 18:11:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A89AD6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626880316; bh=zXgBB90EY6mpVj+jaKfnZqYsDi2k7Z85E2iU/4T3BqQ=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=h57njASUbuwzo4IaMzD2RS8N38iMnrNMIOzb/MxGuYEjDYfN0kwfcMPGlKFK9nlrI m2nHadSVRhg2V122UFGS4Z9RHYqhtcgMZF0FGuJtckeViRTZKpJ3GF3SKsDx54DDxw UU9bEzZypdEsV56Iqby647xKtuKXnCrAm22Q94m0= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B82A36EC55 for ; Wed, 21 Jul 2021 18:11:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B82A36EC55 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1m6Dsn-0002B2-0e; Wed, 21 Jul 2021 18:11:37 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Wed, 21 Jul 2021 18:11:36 +0300 Message-Id: <6069191c12e57726159e04f986fd1cd757a943bb.1626880242.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30A5AB0699C09BB51962E4FF0DD431C8A182A05F538085040F396F37AFC56B25A2E73857C58FDACE6AE5D7F11B2A9F550264630E475DD06BD X-C1DE0DAB: 0D63561A33F958A57B4897902354E43AB7E137FB795C32E4A705A65FF1B8C28F8E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3482189E76C6218D8F1E2FEB3157DF10DD86F074E3FE4B070B7189F592585A302B8D4F545C99410B761D7E09C32AA3244CBAAA94E251489E262599C8F0A5F52966A995755A1445935E729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJX8TSRcb/SjbUjJ0jILXLg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DB21272D08CA68D4383CDB06503F3E9AA83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/1] sql: clear MEM only if necessary X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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