[tarantool-patches] Re: [PATCH 03/12] key_def: cleanup virtual function initialization
Vladimir Davydov
vdavydov.dev at gmail.com
Thu Feb 21 15:05:13 MSK 2019
On Thu, Feb 21, 2019 at 02:01:28PM +0300, Konstantin Osipov wrote:
> * Vladimir Davydov <vdavydov.dev at gmail.com> [19/02/21 13:31]:
>
> Please use subject-verb-object, on other words, key_def_set_func,
> key_def_set_extract_key_func, and so on.
Done on the branch. The new patch is below.
>From aeb32f330b42ec42a1d993d0ac586206e923eab0 Mon Sep 17 00:00:00 2001
From: Vladimir Davydov <vdavydov.dev at gmail.com>
Date: Tue, 19 Feb 2019 14:09:12 +0300
Subject: [PATCH] key_def: cleanup virtual function initialization
- Rename key_def_set_cmp to key_def_set_func, because it sets not only
comparators these days.
- Rename tuple_hash_func_set and tuple_extract_key_set to
key_def_set_hash_func and key_def_set_extract_func, because it's more
like subject-verb-object naming convention used throughout the code.
- Introduce key_def_set_compare_func and use it instead of setting
comparators explicitly in key_def.c.
diff --git a/src/box/key_def.c b/src/box/key_def.c
index 9411ade3..5a75acb3 100644
--- a/src/box/key_def.c
+++ b/src/box/key_def.c
@@ -129,12 +129,11 @@ key_def_delete(struct key_def *def)
}
static void
-key_def_set_cmp(struct key_def *def)
+key_def_set_func(struct key_def *def)
{
- def->tuple_compare = tuple_compare_create(def);
- def->tuple_compare_with_key = tuple_compare_with_key_create(def);
- tuple_hash_func_set(def);
- tuple_extract_key_set(def);
+ key_def_set_compare_func(def);
+ key_def_set_hash_func(def);
+ key_def_set_extract_func(def);
}
static void
@@ -208,7 +207,7 @@ key_def_new(const struct key_part_def *parts, uint32_t part_count)
&path_pool, TUPLE_OFFSET_SLOT_NIL, 0);
}
assert(path_pool == (char *)def + sz);
- key_def_set_cmp(def);
+ key_def_set_func(def);
return def;
}
@@ -261,7 +260,7 @@ box_key_def_new(uint32_t *fields, uint32_t *types, uint32_t part_count)
NULL, COLL_NONE, SORT_ORDER_ASC, NULL, 0,
NULL, TUPLE_OFFSET_SLOT_NIL, 0);
}
- key_def_set_cmp(key_def);
+ key_def_set_func(key_def);
return key_def;
}
@@ -333,7 +332,7 @@ key_def_update_optionality(struct key_def *def, uint32_t min_field_count)
if (def->has_optional_parts)
break;
}
- key_def_set_cmp(def);
+ key_def_set_func(def);
}
int
@@ -686,7 +685,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
part->offset_slot_cache, part->format_epoch);
}
assert(path_pool == (char *)new_def + sz);
- key_def_set_cmp(new_def);
+ key_def_set_func(new_def);
return new_def;
}
diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc
index ded802c7..cbdd150b 100644
--- a/src/box/tuple_compare.cc
+++ b/src/box/tuple_compare.cc
@@ -1049,7 +1049,7 @@ static const tuple_compare_t compare_slowpath_funcs[] = {
tuple_compare_slowpath<true, true, true>
};
-tuple_compare_t
+static tuple_compare_t
tuple_compare_create(const struct key_def *def)
{
int cmp_func_idx = (def->is_nullable ? 1 : 0) +
@@ -1277,7 +1277,7 @@ static const tuple_compare_with_key_t compare_with_key_slowpath_funcs[] = {
tuple_compare_with_key_slowpath<true, true, true>
};
-tuple_compare_with_key_t
+static tuple_compare_with_key_t
tuple_compare_with_key_create(const struct key_def *def)
{
int cmp_func_idx = (def->is_nullable ? 1 : 0) +
@@ -1322,3 +1322,10 @@ tuple_compare_with_key_create(const struct key_def *def)
}
/* }}} tuple_compare_with_key */
+
+void
+key_def_set_compare_func(struct key_def *def)
+{
+ def->tuple_compare = tuple_compare_create(def);
+ def->tuple_compare_with_key = tuple_compare_with_key_create(def);
+}
diff --git a/src/box/tuple_compare.h b/src/box/tuple_compare.h
index e3a63204..f8fa6eb9 100644
--- a/src/box/tuple_compare.h
+++ b/src/box/tuple_compare.h
@@ -30,17 +30,15 @@
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-#include <stddef.h>
#include <stdint.h>
-#include <stdbool.h>
-
-#include "key_def.h"
-#include "tuple.h"
#if defined(__cplusplus)
extern "C" {
#endif /* defined(__cplusplus) */
+struct tuple;
+struct key_def;
+
/**
* Return the length of the longest common prefix of two tuples.
* @param tuple_a first tuple
@@ -53,19 +51,11 @@ tuple_common_key_parts(const struct tuple *tuple_a, const struct tuple *tuple_b,
struct key_def *key_def);
/**
- * Create a comparison function for the key_def
- *
- * @param key_def key_definition
- * @returns a comparision function
+ * Initialize comparator functions for the key_def.
+ * @param key_def key definition
*/
-tuple_compare_t
-tuple_compare_create(const struct key_def *key_def);
-
-/**
- * @copydoc tuple_compare_create()
- */
-tuple_compare_with_key_t
-tuple_compare_with_key_create(const struct key_def *key_def);
+void
+key_def_set_compare_func(struct key_def *def);
#if defined(__cplusplus)
} /* extern "C" */
diff --git a/src/box/tuple_extract_key.cc b/src/box/tuple_extract_key.cc
index 5cf46724..17f06db7 100644
--- a/src/box/tuple_extract_key.cc
+++ b/src/box/tuple_extract_key.cc
@@ -356,7 +356,7 @@ static const tuple_extract_key_t extract_key_slowpath_funcs[] = {
* Initialize tuple_extract_key() and tuple_extract_key_raw()
*/
void
-tuple_extract_key_set(struct key_def *key_def)
+key_def_set_extract_func(struct key_def *key_def)
{
if (key_def_is_sequential(key_def)) {
if (key_def->has_optional_parts) {
diff --git a/src/box/tuple_extract_key.h b/src/box/tuple_extract_key.h
index 8a346595..7be16241 100644
--- a/src/box/tuple_extract_key.h
+++ b/src/box/tuple_extract_key.h
@@ -41,7 +41,7 @@ struct key_def;
* @param key_def key definition
*/
void
-tuple_extract_key_set(struct key_def *key_def);
+key_def_set_extract_func(struct key_def *key_def);
#if defined(__cplusplus)
} /* extern "C" */
diff --git a/src/box/tuple_hash.cc b/src/box/tuple_hash.cc
index 5bfd40cf..5213ae97 100644
--- a/src/box/tuple_hash.cc
+++ b/src/box/tuple_hash.cc
@@ -222,7 +222,7 @@ uint32_t
key_hash_slowpath(const char *key, struct key_def *key_def);
void
-tuple_hash_func_set(struct key_def *key_def) {
+key_def_set_hash_func(struct key_def *key_def) {
if (key_def->is_nullable || key_def->has_json_paths)
goto slowpath;
/*
diff --git a/src/box/tuple_hash.h b/src/box/tuple_hash.h
index abc961bf..d87e3234 100644
--- a/src/box/tuple_hash.h
+++ b/src/box/tuple_hash.h
@@ -42,7 +42,7 @@ extern "C" {
* @param key_def key definition
*/
void
-tuple_hash_func_set(struct key_def *def);
+key_def_set_hash_func(struct key_def *def);
/**
* Compute hash of a tuple field.
More information about the Tarantool-patches
mailing list