From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 03/12] key_def: cleanup virtual function initialization Date: Thu, 21 Feb 2019 13:26:03 +0300 Message-Id: <1aaf38421e27d3cfa4cdb949b8dce36aa8421cfb.1550744027.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: - Rename key_def_set_cmp to key_def_func_set, because it sets not only comparators these days. - Rename tuple_extract_key_set to tuple_extract_key_func_set to match tuple_hash_func_set. - Introduce tuple_compare_func_set and use it instead of setting comparators explicitly in key_def.c. --- src/box/key_def.c | 15 +++++++-------- src/box/tuple_compare.cc | 11 +++++++++-- src/box/tuple_compare.h | 24 +++++++----------------- src/box/tuple_extract_key.cc | 2 +- src/box/tuple_extract_key.h | 2 +- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/box/key_def.c b/src/box/key_def.c index 9411ade3..75e3a0be 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_func_set(struct key_def *def) { - def->tuple_compare = tuple_compare_create(def); - def->tuple_compare_with_key = tuple_compare_with_key_create(def); + tuple_compare_func_set(def); tuple_hash_func_set(def); - tuple_extract_key_set(def); + tuple_extract_key_func_set(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_func_set(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_func_set(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_func_set(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_func_set(new_def); return new_def; } diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc index ded802c7..b8dc350f 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 }; -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 }; -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 +tuple_compare_func_set(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..baecbafe 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 #include -#include - -#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 +tuple_compare_func_set(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..915b6bae 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) +tuple_extract_key_func_set(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..129b0d82 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); +tuple_extract_key_func_set(struct key_def *key_def); #if defined(__cplusplus) } /* extern "C" */ -- 2.11.0