Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type
Date: Mon, 24 May 2021 13:56:30 +0300	[thread overview]
Message-ID: <20210524105630.GA82983@tarantool.org> (raw)
In-Reply-To: <d3ac2493-847e-a3b3-751c-704d1a75063f@tarantool.org>

Hi! Thank you for the review! My answers and diff below.

On Fri, May 21, 2021 at 08:59:14PM +0200, Vladislav Shpilevoy wrote:
> 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().
> 
It is true that it should be not possible to have MEM_Zero flag for
non-VARBINARY value. However, here it is checked that the value is VARBINARY
and if it is, the flag is checked. I think there is nothing wrong here.

Still, In mem_len() I removed one condition and added assert instead.

> >  	*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).
> 
Thanks, fixed. Also fixed in one more place.

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


Diff:

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index f7788021d..1bd70c37f 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1229,7 +1229,8 @@ mem_len(const struct Mem *mem, uint32_t *len)
 {
 	if (!mem_is_bytes(mem))
 		return -1;
-	if (mem->type == MEM_TYPE_BIN && (mem->flags & MEM_Zero) != 0)
+	assert((mem->flags & MEM_Zero) == 0 || mem->type == MEM_TYPE_BIN);
+	if ((mem->flags & MEM_Zero) != 0)
 		*len = mem->n + mem->u.nZero;
 	else
 		*len = mem->n;
@@ -1725,7 +1726,7 @@ mem_bit_not(const struct Mem *mem, struct Mem *result)
 int
 mem_cmp_bool(const struct Mem *a, const struct Mem *b, int *result)
 {
-	if (a->type != MEM_TYPE_BOOL || b->type != MEM_TYPE_BOOL)
+	if ((a->type & b->type & MEM_TYPE_BOOL) == 0)
 		return -1;
 	if (a->u.b == b->u.b)
 		*result = 0;
@@ -2345,7 +2346,7 @@ sqlMemCompare(const Mem * pMem1, const Mem * pMem2, const struct coll * pColl)
 		       (int)(type1 == MEM_TYPE_NULL);
 
 	if (((type1 | type2) & MEM_TYPE_BOOL) != 0) {
-		if (type1 == MEM_TYPE_BOOL && type2 == MEM_TYPE_BOOL) {
+		if ((type1 & type2 & MEM_TYPE_BOOL) != 0) {
 			if (pMem1->u.b == pMem2->u.b)
 				return 0;
 			if (pMem1->u.b)

  reply	other threads:[~2021-05-24 10:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27 16:55 [Tarantool-patches] [PATCH v2 0/3] Replace " Mergen Imeev via Tarantool-patches
2021-04-27 16:55 ` [Tarantool-patches] [PATCH v2 3/3] sql: replace " Mergen Imeev via Tarantool-patches
2021-04-29 21:09   ` Vladislav Shpilevoy via Tarantool-patches
2021-05-17 12:18     ` Mergen Imeev via Tarantool-patches
2021-05-17 12:34       ` Mergen Imeev via Tarantool-patches
2021-05-21 18:59       ` Vladislav Shpilevoy via Tarantool-patches
2021-05-24 10:56         ` Mergen Imeev via Tarantool-patches [this message]
2021-05-24 15:26           ` Vladislav Shpilevoy via Tarantool-patches
2021-05-25 11:13             ` Mergen Imeev via Tarantool-patches
2021-05-25 21:33 ` [Tarantool-patches] [PATCH v2 0/3] Replace " Vladislav Shpilevoy via Tarantool-patches
2021-05-26  8:06 ` Kirill Yukhin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210524105630.GA82983@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 3/3] sql: replace MEM-type flags by enum mem_type' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox