From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 6EB4C26A1E for ; Thu, 8 Aug 2019 10:50:59 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id igswRTlBgbO6 for ; Thu, 8 Aug 2019 10:50:59 -0400 (EDT) Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D9FE9269D6 for ; Thu, 8 Aug 2019 10:50:58 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 3/8] sql: wrap all trim functions in dispatcher Date: Thu, 8 Aug 2019 17:50:47 +0300 Message-Id: <74a116ac889583f76d8617d644f6277073f9fbdd.1565275469.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov A new dispatcher function trim_func calls corresponding trim_ function implementation in relation with number of argc - a count of arguments. This is an important stem to get rid of function's name overloading required for replace FuncDef cache with Tarantool's function cache. Needed for #2200, #4113, #2233 --- src/box/sql/func.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index e00764c3f..f9c0a819e 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1496,6 +1496,32 @@ trim_func_three_args(struct sql_context *context, int argc, sql_value **argv) char_cnt, input_str, input_str_sz); sql_free(char_len); } + +/** + * Normalize args from @a argv input array when it has one, + * two or three args. + * + * This is a dispatcher function that call corresponding + * implementation depending on the number of arguments. +*/ +static void +trim_func(struct sql_context *context, int argc, sql_value **argv) +{ + switch (argc) { + case 1: + trim_func_one_arg(context, argc, argv); + break; + case 2: + trim_func_two_args(context, argc, argv); + break; + case 3: + trim_func_three_args(context, argc, argv); + break; + default: + unreachable(); + } +} + /* * Compute the soundex encoding of a word. * @@ -1840,9 +1866,9 @@ sqlRegisterBuiltinFunctions(void) FIELD_TYPE_BOOLEAN), FUNCTION2(likely, 1, 0, 0, noopFunc, SQL_FUNC_UNLIKELY, FIELD_TYPE_BOOLEAN), - FUNCTION_COLL(trim, 1, 3, 0, trim_func_one_arg), - FUNCTION_COLL(trim, 2, 3, 0, trim_func_two_args), - FUNCTION_COLL(trim, 3, 3, 0, trim_func_three_args), + FUNCTION_COLL(trim, 1, 3, 0, trim_func), + FUNCTION_COLL(trim, 2, 3, 0, trim_func), + FUNCTION_COLL(trim, 3, 3, 0, trim_func), FUNCTION(least, -1, 0, 1, minmaxFunc, FIELD_TYPE_SCALAR), AGGREGATE2(min, 1, 0, 1, minmaxStep, minMaxFinalize, SQL_FUNC_MINMAX, FIELD_TYPE_SCALAR), -- 2.22.0