[Tarantool-patches] [PATCH v5 26/52] sql: move mem_set_bool() and mem_set_double()

imeevma at tarantool.org imeevma at tarantool.org
Fri Apr 9 22:45:35 MSK 2021


Thank you for the review! My answers and new patch below.

I squashed two patches here since they do the same thing - they move functions
from one place to another.


On 30.03.2021 02:04, Vladislav Shpilevoy wrote:
> Thanks for the patch!
>
> See 2 comments below.
>
> On 23.03.2021 10:35, Mergen Imeev via Tarantool-patches wrote:
>> This patch introduces mem_set_double(). Function mem_set_double()
>> clears MEM and sets it to given unsigned value.
>
> 1. It is not about unsigned.
>
Fixed.

>> Part of #5818
>> ---
>> diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
>> index bf3690b7c..49b4e4b1a 100644
>> --- a/src/box/sql/mem.h
>> +++ b/src/box/sql/mem.h
>> @@ -419,10 +422,6 @@ int sqlVdbeMemClearAndResize(struct Mem * pMem, int n);
>>  void
>>  mem_set_ptr(struct Mem *mem, void *ptr);
>>  
>> -/** Set double value and MEM_Real flag. */
>> -void
>> -mem_set_double(struct Mem *mem, double value);
>
> 2. Why do you move these functions and their definitions? What was
> wrong with keeping them in place?
>
I think it is better when all these mem_set_*() functions in one block. This is
the only reason, I believe.

>> -
>>  int
>>  sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *));
>>  void
>>


New patch:

commit fa3fc18275f01e824c6ca8f0bcbf27cb857fb3a8
Author: Mergen Imeev <imeevma at gmail.com>
Date:   Mon Mar 15 12:42:59 2021 +0300

    sql: move mem_set_bool() and mem_set_double()
    
    This patch performs a small refactoring of mem_set_double() and moves
    this function and mem_set_bool() to another place so that they are part
    of the code block containing all mem_set_*() functions.
    
    Part of #5818

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index d79d471bc..c16f3a28a 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -291,6 +291,26 @@ mem_set_uint(struct Mem *mem, uint64_t value)
 	mem->field_type = FIELD_TYPE_UNSIGNED;
 }
 
+void
+mem_set_bool(struct Mem *mem, bool value)
+{
+	mem_clear(mem);
+	mem->u.b = value;
+	mem->flags = MEM_Bool;
+	mem->field_type = FIELD_TYPE_BOOLEAN;
+}
+
+void
+mem_set_double(struct Mem *mem, double value)
+{
+	mem_clear(mem);
+	mem->field_type = FIELD_TYPE_DOUBLE;
+	if (sqlIsNaN(value))
+		return;
+	mem->u.r = value;
+	mem->flags = MEM_Real;
+}
+
 int
 mem_copy(struct Mem *to, const struct Mem *from)
 {
@@ -1945,15 +1965,6 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
 	return 0;
 }
 
-void
-mem_set_bool(struct Mem *mem, bool value)
-{
-	mem_clear(mem);
-	mem->u.b = value;
-	mem->flags = MEM_Bool;
-	mem->field_type = FIELD_TYPE_BOOLEAN;
-}
-
 void
 mem_set_ptr(struct Mem *mem, void *ptr)
 {
@@ -1962,17 +1973,6 @@ mem_set_ptr(struct Mem *mem, void *ptr)
 	mem->u.p = ptr;
 }
 
-void
-mem_set_double(struct Mem *mem, double value)
-{
-	mem_clear(mem);
-	if (sqlIsNaN(value))
-		return;
-	mem->u.r = value;
-	MemSetTypeFlag(mem, MEM_Real);
-	mem->field_type = FIELD_TYPE_DOUBLE;
-}
-
 /*
  * Change the value of a Mem to be a string or a BLOB.
  *
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 8bc058d3b..8022f53d8 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -174,6 +174,14 @@ mem_set_int(struct Mem *mem, int64_t value, bool is_neg);
 void
 mem_set_uint(struct Mem *mem, uint64_t value);
 
+/** Clear MEM and set it to BOOLEAN. */
+void
+mem_set_bool(struct Mem *mem, bool value);
+
+/** Clear MEM and set it to DOUBLE. */
+void
+mem_set_double(struct Mem *mem, double value);
+
 /**
  * Copy content of MEM from one MEM to another. In case source MEM contains
  * string or binary and allocation type is not STATIC, this value is copied to
@@ -444,9 +452,6 @@ mem_convert_to_numeric(struct Mem *mem, enum field_type type);
 int sqlVdbeMemGrow(struct Mem * pMem, int n, int preserve);
 int sqlVdbeMemClearAndResize(struct Mem * pMem, int n);
 
-void
-mem_set_bool(struct Mem *mem, bool value);
-
 /**
  * Set VDBE memory register with given pointer as a data.
  * @param mem VDBE memory register to update.
@@ -455,10 +460,6 @@ mem_set_bool(struct Mem *mem, bool value);
 void
 mem_set_ptr(struct Mem *mem, void *ptr);
 
-/** Set double value and MEM_Real flag. */
-void
-mem_set_double(struct Mem *mem, double value);
-
 int
 sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *));
 void


More information about the Tarantool-patches mailing list