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 CDACA6EC5D; Fri, 9 Apr 2021 19:59:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CDACA6EC5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617987589; bh=Vqm7Spw5uZihnh9KBOrSz2wQ4HNpgICVPbM7XTr6180=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=vF4BMoorhNo9y0q4YpXVUnzj3cdiA+QWFY51jPfV1p1JFgde56DcJ+eVret0pGkqL 1qZ4S+K80tdF+eUrEEDuJHlYewkU/vCGOWjpbGlQCWW/BlBqpnFt5MlQF/2xy5ShUE mlhZ1+6h5UZpTCZ3tvwdGZG2fe7BdN7yb/f4KojE= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [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 7F1896EC5D for ; Fri, 9 Apr 2021 19:59:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7F1896EC5D Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lUuTz-0000jo-MS; Fri, 09 Apr 2021 19:59:48 +0300 To: v.shpilevoy@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 9 Apr 2021 19:59:47 +0300 Message-Id: <818bc80a29d94bd46ede4e88180d11c041d67cd0.1617984948.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480257C85EA0BB7A95D0F00AE41BB9A5343182A05F538085040C80E529C9DDE062D11CCB05B09A490230847466B513DCF707D7234E367FB63A2 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78BAADB77C21FF6F2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370FDF1CE57EA9D07C8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B25EB03F3E9F59DD6DA561318BA2C24FF1B10649542A97EE81D2E47CDBA5A96583C09775C1D3CA48CFE478A468B35FE767117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE77E7E81EEA8A9722B8941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FC0F9454058DFE53C35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CD0035DD76F8A8A4F16824A7080ED1B18D74C0BA32E7B0C339C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F05B761BB9C2AA44F3558FC7F1000D876A68A209AD7691F54A9E784D92929237B80C04827F230CD31D7E09C32AA3244C80A728D6DC0D04A091B2820C8153FEE0FE8DA44ABE2443F7FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyO2lHpuZu4RSSnlMxENndQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382273D3D7BBBEE10F4B733C627C93FAB7D783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v5 06/52] sql: refactor port_vdbemem_*() functions 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" This patch simplifies port_vdbemem_dump_lua() and port_vdbemem_get_msgpack() functions. Part of #5818 --- src/box/sql/mem.c | 85 +++++++++-------------------------------------- 1 file changed, 16 insertions(+), 69 deletions(-) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index d28b9a958..25f5f2f2d 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -2365,33 +2365,26 @@ port_vdbemem_dump_lua(struct port *base, struct lua_State *L, bool is_flat) struct port_vdbemem *port = (struct port_vdbemem *) base; assert(is_flat == true); for (uint32_t i = 0; i < port->mem_count; i++) { - sql_value *param = - (sql_value *)((struct Mem *)port->mem + i); - switch (sql_value_type(param)) { - case MP_INT: - luaL_pushint64(L, sql_value_int64(param)); + struct Mem *mem = (struct Mem *)port->mem + i; + switch (mem->flags & MEM_PURE_TYPE_MASK) { + case MEM_Int: + luaL_pushint64(L, mem->u.i); break; - case MP_UINT: - luaL_pushuint64(L, sql_value_uint64(param)); + case MEM_UInt: + luaL_pushuint64(L, mem->u.u); break; - case MP_DOUBLE: - lua_pushnumber(L, sql_value_double(param)); + case MEM_Real: + lua_pushnumber(L, mem->u.r); break; - case MP_STR: - lua_pushlstring(L, (const char *)sql_value_text(param), - (size_t)sql_value_bytes(param)); + case MEM_Str: + case MEM_Blob: + lua_pushlstring(L, mem->z, mem->n); break; - case MP_BIN: - case MP_ARRAY: - case MP_MAP: - lua_pushlstring(L, sql_value_blob(param), - (size_t) sql_value_bytes(param)); - break; - case MP_NIL: + case MEM_Null: lua_pushnil(L); break; - case MP_BOOL: - lua_pushboolean(L, sql_value_boolean(param)); + case MEM_Bool: + lua_pushboolean(L, mem->u.b); break; default: unreachable(); @@ -2410,54 +2403,8 @@ port_vdbemem_get_msgpack(struct port *base, uint32_t *size) mpstream_init(&stream, region, region_reserve_cb, region_alloc_cb, set_encode_error, &is_error); mpstream_encode_array(&stream, port->mem_count); - for (uint32_t i = 0; i < port->mem_count && !is_error; i++) { - sql_value *param = - (sql_value *)((struct Mem *)port->mem + i); - switch (sql_value_type(param)) { - case MP_INT: { - sql_int64 val = sql_value_int64(param); - if (val < 0) { - mpstream_encode_int(&stream, val); - break; - } - FALLTHROUGH; - } - case MP_UINT: { - sql_uint64 val = sql_value_uint64(param); - mpstream_encode_uint(&stream, val); - break; - } - case MP_DOUBLE: { - mpstream_encode_double(&stream, - sql_value_double(param)); - break; - } - case MP_STR: { - const char *str = (const char *) sql_value_text(param); - mpstream_encode_strn(&stream, str, - sql_value_bytes(param)); - break; - } - case MP_BIN: - case MP_ARRAY: - case MP_MAP: { - mpstream_encode_binl(&stream, sql_value_bytes(param)); - mpstream_memcpy(&stream, sql_value_blob(param), - sql_value_bytes(param)); - break; - } - case MP_NIL: { - mpstream_encode_nil(&stream); - break; - } - case MP_BOOL: { - mpstream_encode_bool(&stream, sql_value_boolean(param)); - break; - } - default: - unreachable(); - } - } + for (uint32_t i = 0; i < port->mem_count && !is_error; i++) + mpstream_encode_vdbe_mem(&stream, (struct Mem *)port->mem + i); mpstream_flush(&stream); *size = region_used(region) - region_svp; if (is_error) -- 2.25.1