[Tarantool-patches] [PATCH v1 2/7] sql: remove implicit cast from comparison opcodes

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Aug 6 03:13:31 MSK 2021


>>> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
>>> index d143ce364..62f58def9 100644
>>> --- a/src/box/sql/vdbe.c
>>> +++ b/src/box/sql/vdbe.c
>> <...>
>>
>>> -	switch( pOp->opcode) {
>>> -	case OP_Eq:    res2 = res==0;     break;
>>> -	case OP_Ne:    res2 = res;        break;
>>> -	case OP_Lt:    res2 = res<0;      break;
>>> -	case OP_Le:    res2 = res<=0;     break;
>>> -	case OP_Gt:    res2 = res>0;      break;
>>> -	default:       res2 = res>=0;     break;
>>> +	bool result;
>>> +	switch(pOp->opcode) {
>>
>> 3. It does not look good to have a second switch-case here. But I
>> can't find a better solution right away. We can't wrap this all
>> into a function, because need to make goto abort_due_to_error and
>> goto jump_to_p2 in some places. Up to you if you want to find a
>> way to fix it.
>>
>> As a side note, the code now is incomparably simpler than it was.
>> It is getting actually understable, nice.
>>
> I divided these 6 opcode to two grops: EQ & NE and all others. ALso, I actually
> can avoid branching in any groups using somethins like:
> 
> int op = pOp->opcode;
> bool result = (op == OP_Lt && cmp_res < 0) || (op == OP_Gt && cmp_res > 0) || ...
> But not sure that it will be easier to read. What do you think?

That is still branching - && and || are not better than 'if' usually.
Up to you.


More information about the Tarantool-patches mailing list