[Tarantool-patches] [PATCH v1 1/8] sql: refactor ABS() funcion

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sat Oct 9 00:55:33 MSK 2021


Hi! Thanks for the patch!

On 01.10.2021 18:29, imeevma at tarantool.org wrote:
> Part of #4145
> ---
>  src/box/sql/func.c | 83 +++++++++++++++++-----------------------------
>  1 file changed, 30 insertions(+), 53 deletions(-)
> 
> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> index b23636d7e..54b03f359 100644
> --- a/src/box/sql/func.c
> +++ b/src/box/sql/func.c
> @@ -237,6 +237,32 @@ step_group_concat(struct sql_context *ctx, int argc, struct Mem *argv)
>  		ctx->is_aborted = true;
>  }
>  
> +/** Implementations of the ABS() function. */
> +static void
> +func_abs_int(struct sql_context *ctx, int argc, struct Mem *argv)
> +{
> +	assert(argc == 1);
> +	(void)argc;
> +	struct Mem *arg = &argv[0];
> +	if (arg->type == MEM_TYPE_NULL)
> +		return;

1. Need mem_is_null(). The same for the other places if there
are more.

> +	assert(mem_is_int(arg));
> +	uint64_t u = mem_is_uint(arg) ? arg->u.u : (uint64_t)-arg->u.i;

2. You could make return when mem_is_uint(). It would remove '?' and
mem_set_uint() which would calls mem_clear() inside.

> +	mem_set_uint(ctx->pOut, u);


More information about the Tarantool-patches mailing list