From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v6 1/3] box: refactor key_def_set_compare_func routine Date: Wed, 13 Mar 2019 15:15:37 +0300 Message-Id: <34cf8ed7af4b1da74a89a260562abe08526cd4e8.1552478226.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov List-ID: Refactored tuple_compare_create and tuple_compare_with_key_create routines to set corresponding key_def field by it's own instead of returning pointer to function. This is required as in further patches we should set two key_def pointers: for hinted and for non-hinted routine version. Needed for #3961 --- src/box/tuple_compare.cc | 62 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc index cf4519ccb..1bcff2ca3 100644 --- a/src/box/tuple_compare.cc +++ b/src/box/tuple_compare.cc @@ -1049,21 +1049,26 @@ static const tuple_compare_t compare_slowpath_funcs[] = { tuple_compare_slowpath }; -static tuple_compare_t -tuple_compare_create(const struct key_def *def) +void +key_def_set_tuple_compare(struct key_def *def) { int cmp_func_idx = (def->is_nullable ? 1 : 0) + 2 * (def->has_optional_parts ? 1 : 0) + 4 * (def->has_json_paths ? 1 : 0); if (def->is_nullable) { if (key_def_is_sequential(def)) { - if (def->has_optional_parts) - return tuple_compare_sequential; - else - return tuple_compare_sequential; + if (def->has_optional_parts) { + def->tuple_compare = + tuple_compare_sequential; + } else { + def->tuple_compare = + tuple_compare_sequential; + } } else { - return compare_slowpath_funcs[cmp_func_idx]; + def->tuple_compare = + compare_slowpath_funcs[cmp_func_idx]; } + return; } assert(! def->has_optional_parts); if (!key_def_has_collation(def) && !def->has_json_paths) { @@ -1078,13 +1083,15 @@ tuple_compare_create(const struct key_def *def) cmp_arr[k].p[i * 2 + 1]) break; if (i == def->part_count && - cmp_arr[k].p[i * 2] == UINT32_MAX) - return cmp_arr[k].f; + cmp_arr[k].p[i * 2] == UINT32_MAX) { + def->tuple_compare = cmp_arr[k].f; + return; + } } } - return key_def_is_sequential(def) ? - tuple_compare_sequential : - compare_slowpath_funcs[cmp_func_idx]; + def->tuple_compare = key_def_is_sequential(def) ? + tuple_compare_sequential : + compare_slowpath_funcs[cmp_func_idx]; } /* }}} tuple_compare */ @@ -1277,8 +1284,8 @@ static const tuple_compare_with_key_t compare_with_key_slowpath_funcs[] = { tuple_compare_with_key_slowpath }; -static tuple_compare_with_key_t -tuple_compare_with_key_create(const struct key_def *def) +void +key_def_set_tuple_compare_with_key(struct key_def *def) { int cmp_func_idx = (def->is_nullable ? 1 : 0) + 2 * (def->has_optional_parts ? 1 : 0) + @@ -1286,15 +1293,19 @@ tuple_compare_with_key_create(const struct key_def *def) if (def->is_nullable) { if (key_def_is_sequential(def)) { if (def->has_optional_parts) { - return tuple_compare_with_key_sequentialtuple_compare_with_key = + tuple_compare_with_key_sequential; } else { - return tuple_compare_with_key_sequentialtuple_compare_with_key = + tuple_compare_with_key_sequential; } } else { - return compare_with_key_slowpath_funcs[cmp_func_idx]; + def->tuple_compare_with_key = + compare_with_key_slowpath_funcs[cmp_func_idx]; } + return; } assert(! def->has_optional_parts); if (!key_def_has_collation(def) && !def->has_json_paths) { @@ -1312,13 +1323,16 @@ tuple_compare_with_key_create(const struct key_def *def) break; } } - if (i == def->part_count) - return cmp_wk_arr[k].f; + if (i == def->part_count) { + def->tuple_compare_with_key = cmp_wk_arr[k].f; + return; + } } } - return key_def_is_sequential(def) ? - tuple_compare_with_key_sequential : - compare_with_key_slowpath_funcs[cmp_func_idx]; + def->tuple_compare_with_key = + key_def_is_sequential(def) ? + tuple_compare_with_key_sequential : + compare_with_key_slowpath_funcs[cmp_func_idx]; } /* }}} tuple_compare_with_key */ @@ -1326,6 +1340,6 @@ tuple_compare_with_key_create(const struct key_def *def) 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); + key_def_set_tuple_compare(def); + key_def_set_tuple_compare_with_key(def); } -- 2.21.0