[Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri May 21 21:59:14 MSK 2021


Hi! Thanks for the fixes!

See 2 small comments below.

> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index b6ff6397f..f7788021d 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -1155,11 +1214,11 @@ mem_get_str0(const struct Mem *mem, const char **s)
>  int
>  mem_get_bin(const struct Mem *mem, const char **s)
>  {
> -	if ((mem->flags & MEM_Str) != 0) {
> +	if (mem->type == MEM_TYPE_STR) {
>  		*s = mem->n > 0 ? mem->z : NULL;
>  		return 0;
>  	}
> -	if ((mem->flags & MEM_Blob) == 0 || (mem->flags & MEM_Zero) != 0)
> +	if (mem->type != MEM_TYPE_BIN || (mem->flags & MEM_Zero) != 0)
>  		return -1;

1. AFAIR, it is not possible to have MEM_Zero for non-bin. Which makes
the second condition unreachable, right? The same in mem_len().

>  	*s = mem->z;
>  	return 0;
> @@ -1644,14 +1717,15 @@ mem_bit_not(const struct Mem *mem, struct Mem *result)
>  		return -1;
>  	}
>  	result->u.i = ~i;
> -	result->flags = result->u.i < 0 ? MEM_Int : MEM_UInt;
> +	result->type = result->u.i < 0 ? MEM_TYPE_INT : MEM_TYPE_UINT;
> +	assert(result->flags == 0);
>  	return 0;
>  }
>  
>  int
>  mem_cmp_bool(const struct Mem *a, const struct Mem *b, int *result)
>  {
> -	if ((a->flags & b->flags & MEM_Bool) == 0)
> +	if (a->type != MEM_TYPE_BOOL || b->type != MEM_TYPE_BOOL)

2. You could leave the old way so as to avoid || (branching).

>  		return -1;
>  	if (a->u.b == b->u.b)
>  		*result = 0;


More information about the Tarantool-patches mailing list