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 48D3571229; Fri, 29 Oct 2021 01:12:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 48D3571229 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635459148; bh=twj0OVFvDJdhcE7dkFncQpU7hBpefryEtA28tDqbUV0=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=hdYF3swhooGHYISD3FsJ+smkcxCw6N4AnrRyrDv11tflRU7F6yFT0RhQJuZP+kFnR 6E+QnCgCewAst3Fuk5dNjghn6P19XbltCL0hzSWIJZy1/esvr65+Z7uEezdZCtJuAc L1MWOY8YYMzIVcB7R23P9gI5dZL8YvS6pR67lBL8= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [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 0C7D971224 for ; Fri, 29 Oct 2021 01:12:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0C7D971224 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mgDdK-0001q5-Fa; Fri, 29 Oct 2021 01:12:26 +0300 Message-ID: <6c8b2277-4837-02fd-5cdc-0ccba9f1318f@tarantool.org> Date: Fri, 29 Oct 2021 00:12:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Content-Language: en-US To: Mergen Imeev , tarantool-patches@dev.tarantool.org References: <9424a550a61d32fd8ec2e578ea9cc00b45fbe4ed.1633105483.git.imeevma@gmail.com> <20211020170523.GD203963@tarantool.org> In-Reply-To: <20211020170523.GD203963@tarantool.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9E6B4260954843F6F6CA2F287E066BD93F73BF403D6E2966600894C459B0CD1B95040C22D8E8417BA84ABD050F2ADD04B08357E0F7F63E0005E522EEE8CA89B86 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F6EE1C40B2E8BE15EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063727BBC20C3D5F36038638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D883BEADA656C3EB7725B0E717949D9ED9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6CF11E2829993B7FCEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50569982430092E461C3BEB1FDD4FF854B9 X-C1DE0DAB: 0D63561A33F958A51035406EFC51393CC0323D9698738129A07B2413EF5F06AAD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75C29D03FC76C37677410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AE88D5ADEBE7C98320108376D48DA3055261EEAB7AB4AEBB0789C2967D2D3EA25115BCFB0E62932B1D7E09C32AA3244CFB508413CF3BB7AA606D0493663E5C8DE3D93501275E802F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojdMRfVmNkPDiK/5w/dzXqsw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D9CF8452B4325345D27FB0744FD77E8AF3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 5/8] sql: rework TRIM() function 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 fixes! See 3 comments below. > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index d36c83501..1294ff5b3 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -344,6 +344,178 @@ func_nullif(struct sql_context *ctx, int argc, struct Mem *argv) > ctx->is_aborted = true; > } > > +static inline void > +return_empty_str(struct sql_context *ctx, bool is_str) 1. It is called in a single place with is_str = false. Could we maybe inline it? > +{ > + return is_str ? mem_set_str_static(ctx->pOut, "", 0) : > + mem_set_bin_static(ctx->pOut, "", 0); > +} ... > + > +static void > +func_trim_str(struct sql_context *ctx, int argc, struct Mem *argv) > +{ > + if (mem_is_null(&argv[0]) || (argc == 3 && mem_is_null(&argv[2]))) > + return; > + assert(argc == 2 || (argc == 3 && mem_is_str(&argv[2]))); > + assert(mem_is_str(&argv[0]) && mem_is_uint(&argv[1])); > + const char *str = argv[0].z; > + int size = argv[0].n; > + const char *chars; > + int chars_size; > + if (argc == 3) { > + chars = argv[2].z; > + chars_size = argv[2].n; > + } else { > + chars = " "; > + chars_size = 1; > + } > + > + uint8_t *chars_len = sqlDbMallocRawNN(sql_get(), > + chars_size * sizeof(uint8_t)); 2. Could use fiber region here. Up to you. > + if (chars_len == NULL) { > + ctx->is_aborted = true; > + return; > + } > + int chars_count = 0; > + > + UErrorCode err = U_ZERO_ERROR; > + const char *pos_start = chars; > + const char *pos_end = chars + chars_size; > + while (pos_start < pos_end) { > + const char *cur = pos_start; > + ucnv_getNextUChar(icu_utf8_conv, &pos_start, pos_end, &err); > + chars_len[chars_count++] = pos_start - cur; > + } > + > + uint64_t flags = argv[1].u.u; > + int end = trim_str_end(str, size, chars, chars_len, chars_count, flags); > + int start = trim_str_start(str, end, chars, chars_len, chars_count, > + flags); 3. The second line of the call is misaligned a bit.