[Tarantool-patches] [PATCH v4 27/53] sql: refactor mem_set_double()

imeevma at tarantool.org imeevma at tarantool.org
Tue Mar 23 12:35:53 MSK 2021


This patch introduces mem_set_double(). Function mem_set_double()
clears MEM and sets it to given unsigned value.

Part of #5818
---
 src/box/sql/mem.c | 22 +++++++++++-----------
 src/box/sql/mem.h |  7 +++----
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 42a65d714..47a71fb30 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -290,6 +290,17 @@ mem_set_boolean(struct Mem *mem, bool value)
 	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)
 {
@@ -1916,17 +1927,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 bf3690b7c..49b4e4b1a 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -179,6 +179,9 @@ mem_set_unsigned(struct Mem *mem, uint64_t value);
 void
 mem_set_boolean(struct Mem *mem, bool value);
 
+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
@@ -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);
-
 int
 sqlVdbeMemSetStr(struct Mem *, const char *, int, u8, void (*)(void *));
 void
-- 
2.25.1



More information about the Tarantool-patches mailing list