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 EBEDF6C185; Tue, 30 Mar 2021 02:12:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EBEDF6C185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1617059579; bh=8lqY2slLxT2nvdy1EguwbF5gK7Kv7k86Af4BGsSyPJg=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=OXZD+DW+dylpkoK7vbkCMnZiK2/N8gF+t8fgWyz36wqOI92ncPJ4xWcFsfmp1FyuW 9uQrFJjOT1qZTrkREf/qMpmgN3NzRxcwW5dyuiY4hnhxgkY93QFfE/g+SNoYNEUHUp ydgWupgB4wwQTrsss+e+dC6L4Nv+0F1sQbb4pk30= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 8D8526BD0B for ; Tue, 30 Mar 2021 02:07:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8D8526BD0B Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lR0zC-00038I-P5; Tue, 30 Mar 2021 02:07:55 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <32e990d3f1683a87eba40d77874b4b3227ae1e71.1616491731.git.imeevma@gmail.com> Message-ID: <497b6583-ebc8-2f2c-8337-06549d436b04@tarantool.org> Date: Tue, 30 Mar 2021 01:07:53 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <32e990d3f1683a87eba40d77874b4b3227ae1e71.1616491731.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9ED7173E37F4E32947287414FD1D04A09E656A5F3377C994A182A05F5380850401B65FF928E16A09BA1101343D370B1FF955DFEF0364869E8003FE4D2132CEA13 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE711269A7C2F827F16EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371A4E0E763A740679EA1F7E6F0F101C67CDEEF6D7F21E0D1D174C73DBBBFC7664AF392B77D6B6B3816AB52DEDD690DE188BFCE54215300FE6389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B636DA1BED736F9328CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CFC5EA940A35A165FF2DBA43225CD8A89FC0F9454058DFE53C262FEC7FBD7D1F5BB5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C97831604167623C6AC6DE99F3B6BFDA6AA5C4 X-C1DE0DAB: 0D63561A33F958A5C959B1DE714315AE0B572ACA1408DB3249B09D1A03707C53D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344EF254DC71474AA3F5424A6B5E107C0E12845A043CDDD777C37EB63FACD06C0AC11F4F31BEEF215C1D7E09C32AA3244C057BAF92249AA790CB537A06563DED1605AB220A9D022EBCFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojljIiQOC84rQkg2dpK903Gw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638227ADFC3F783CF737E35D354CD69779F483841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v4 44/53] sql: introduce mem_convert_to_string() 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See 3 comments below. On 23.03.2021 10:36, imeevma@tarantool.org wrote: > This patch introduces mem_convert_to_string(). This function is used to > convert MEM to MEM contains string value. > > Part of #5818 > --- > src/box/sql/mem.c | 197 ++++++++++++++++++++++++++++++---------------- > src/box/sql/mem.h | 7 +- > 2 files changed, 133 insertions(+), 71 deletions(-) > > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 8600b5c41..262f48aca 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -818,6 +818,131 @@ mem_convert_to_number(struct Mem *mem) <...> > + > +static inline int > +mem_convert_boolean_to_string(struct Mem *mem) > +{ > + const char *str = mem->u.b ? "TRUE" : "FALSE"; > + return mem_copy_string0(mem, str); 1. This can be a static string. Because the string constants are not going anywhere, can ref them as is. <...> > + > +int > +mem_convert_to_string0(struct Mem *mem) > +{ > + if ((mem->flags & MEM_Str) != 0 && (mem->flags & MEM_Term) != 0) 2. Can be done in one check: (mem->flags & (MEM_Str | MEM_Term)) == (MEM_Str | MEM_Term) > + return 0; > + if ((mem->flags & MEM_Str) != 0) > + return mem_convert_string_to_string0(mem); > + if ((mem->flags & (MEM_Int | MEM_UInt)) != 0) > + return mem_convert_integer_to_string(mem); > + if ((mem->flags & MEM_Real) != 0) > + return mem_convert_double_to_string(mem); > + if ((mem->flags & MEM_Bool) != 0) > + return mem_convert_boolean_to_string(mem); > + if ((mem->flags & MEM_Blob) != 0) { > + if ((mem->flags & MEM_Subtype) == 0) > + return mem_convert_binary_to_string0(mem); > + if (mp_typeof(*mem->z) == MP_MAP) > + return mem_convert_map_to_string(mem); > + return mem_convert_array_to_string(mem); > + } > + return -1; > +} > + > +int > +mem_convert_to_string(struct Mem *mem) 3. Why would you need a not terminated string? The old function always terminated the strings AFAIS. > +{ > + if ((mem->flags & MEM_Str) != 0) > + return 0; > + if ((mem->flags & (MEM_Int | MEM_UInt)) != 0) > + return mem_convert_integer_to_string(mem); > + if ((mem->flags & MEM_Real) != 0) > + return mem_convert_double_to_string(mem); > + if ((mem->flags & MEM_Bool) != 0) > + return mem_convert_boolean_to_string(mem); > + if ((mem->flags & MEM_Blob) != 0) { > + if ((mem->flags & MEM_Subtype) == 0) > + return mem_convert_binary_to_string(mem); > + if (mp_typeof(*mem->z) == MP_MAP) > + return mem_convert_map_to_string(mem); > + return mem_convert_array_to_string(mem); > + } > + return -1; > +} > + > int > mem_copy(struct Mem *to, const struct Mem *from) > {