From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org,
Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: Re: [tarantool-patches] Re: [PATCH v3 1/7] box: cleanup key_def virtual extract_key setter
Date: Wed, 3 Apr 2019 19:22:56 +0300 [thread overview]
Message-ID: <7f1136a6-055a-7713-cb6c-91a51a53ec8d@tarantool.org> (raw)
In-Reply-To: <20190403124215.7ngokicqvqceahid@esperanza>
> Yeah, this looks better. However, I'd also replace set_extract_func with
> plain if-else-if - it would take only a couple lines longer, but look
> more straightforward IMO.
I don't mind. Updated version is on the branch.
======================================================
This patch inspired by 082cffca4dba attempts to simplify setting
appropriate tuple_extract_key pointer for plain and json indexes
in key_def_set_extract_func routine.
Being split to plain and json blocks this code becomes easier
to understand and extend.
In further patches we need to introduce is_multikey branch and
without this refactoring required amendments turn the
key_def_set_extract_func code into a mess.
Needed for #1257
---
| 97 +++++++++++++++++++-----------------
1 file changed, 52 insertions(+), 45 deletions(-)
--git a/src/box/tuple_extract_key.cc b/src/box/tuple_extract_key.cc
index 0a8337102..28ca80cf8 100644
--- a/src/box/tuple_extract_key.cc
+++ b/src/box/tuple_extract_key.cc
@@ -341,61 +341,68 @@ tuple_extract_key_slowpath_raw(const char *data, const char *data_end,
return key;
}
-static const tuple_extract_key_t extract_key_slowpath_funcs[] = {
- tuple_extract_key_slowpath<false, false, false>,
- tuple_extract_key_slowpath<true, false, false>,
- tuple_extract_key_slowpath<false, true, false>,
- tuple_extract_key_slowpath<true, true, false>,
- tuple_extract_key_slowpath<false, false, true>,
- tuple_extract_key_slowpath<true, false, true>,
- tuple_extract_key_slowpath<false, true, true>,
- tuple_extract_key_slowpath<true, true, true>
-};
-
/**
* Initialize tuple_extract_key() and tuple_extract_key_raw()
*/
-void
-key_def_set_extract_func(struct key_def *key_def)
+template<bool contains_sequential_parts, bool has_optional_parts>
+static void
+key_def_set_extract_func_plain(struct key_def *def)
{
- if (key_def_is_sequential(key_def)) {
- if (key_def->has_optional_parts) {
- assert(key_def->is_nullable);
- key_def->tuple_extract_key =
- tuple_extract_key_sequential<true>;
- key_def->tuple_extract_key_raw =
- tuple_extract_key_sequential_raw<true>;
- } else {
- key_def->tuple_extract_key =
- tuple_extract_key_sequential<false>;
- key_def->tuple_extract_key_raw =
- tuple_extract_key_sequential_raw<false>;
- }
+ assert(!def->has_json_paths);
+ if (key_def_is_sequential(def)) {
+ assert(contains_sequential_parts || def->part_count == 1);
+ def->tuple_extract_key = tuple_extract_key_sequential
+ <has_optional_parts>;
+ def->tuple_extract_key_raw = tuple_extract_key_sequential_raw
+ <has_optional_parts>;
} else {
- int func_idx =
- (key_def_contains_sequential_parts(key_def) ? 1 : 0) +
- 2 * (key_def->has_optional_parts ? 1 : 0) +
- 4 * (key_def->has_json_paths ? 1 : 0);
- key_def->tuple_extract_key =
- extract_key_slowpath_funcs[func_idx];
- assert(!key_def->has_optional_parts || key_def->is_nullable);
+ def->tuple_extract_key = tuple_extract_key_slowpath
+ <contains_sequential_parts,
+ has_optional_parts, false>;
+ def->tuple_extract_key_raw = tuple_extract_key_slowpath_raw
+ <has_optional_parts, false>;
}
- if (key_def->has_optional_parts) {
- assert(key_def->is_nullable);
- if (key_def->has_json_paths) {
- key_def->tuple_extract_key_raw =
- tuple_extract_key_slowpath_raw<true, true>;
+}
+
+template<bool contains_sequential_parts, bool has_optional_parts>
+static void
+key_def_set_extract_func_json(struct key_def *def)
+{
+ assert(def->has_json_paths);
+ def->tuple_extract_key = tuple_extract_key_slowpath
+ <contains_sequential_parts,
+ has_optional_parts, true>;
+ def->tuple_extract_key_raw = tuple_extract_key_slowpath_raw
+ <has_optional_parts, true>;
+}
+
+void
+key_def_set_extract_func(struct key_def *key_def)
+{
+ bool contains_sequential_parts =
+ key_def_contains_sequential_parts(key_def);
+ bool has_optional_parts = key_def->has_optional_parts;
+ if (!key_def->has_json_paths) {
+ if (!contains_sequential_parts && !has_optional_parts) {
+ key_def_set_extract_func_plain<false, false>(key_def);
+ } else if (!contains_sequential_parts && has_optional_parts) {
+ key_def_set_extract_func_plain<false, true>(key_def);
+ } else if (contains_sequential_parts && !has_optional_parts) {
+ key_def_set_extract_func_plain<true, false>(key_def);
} else {
- key_def->tuple_extract_key_raw =
- tuple_extract_key_slowpath_raw<true, false>;
+ assert(contains_sequential_parts && has_optional_parts);
+ key_def_set_extract_func_plain<true, true>(key_def);
}
} else {
- if (key_def->has_json_paths) {
- key_def->tuple_extract_key_raw =
- tuple_extract_key_slowpath_raw<false, true>;
+ if (!contains_sequential_parts && !has_optional_parts) {
+ key_def_set_extract_func_json<false, false>(key_def);
+ } else if (!contains_sequential_parts && has_optional_parts) {
+ key_def_set_extract_func_json<false, true>(key_def);
+ } else if (contains_sequential_parts && !has_optional_parts) {
+ key_def_set_extract_func_json<true, false>(key_def);
} else {
- key_def->tuple_extract_key_raw =
- tuple_extract_key_slowpath_raw<false, false>;
+ assert(contains_sequential_parts && has_optional_parts);
+ key_def_set_extract_func_json<true, true>(key_def);
}
}
}
--
2.21.0
next prev parent reply other threads:[~2019-04-03 16:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-02 15:49 [PATCH v3 0/7] box: introduce multikey indexes in memtx Kirill Shcherbatov
2019-04-02 15:49 ` [PATCH v3 1/7] box: cleanup key_def virtual extract_key setter Kirill Shcherbatov
2019-04-03 12:42 ` Vladimir Davydov
2019-04-03 16:22 ` Kirill Shcherbatov [this message]
2019-04-03 18:01 ` [tarantool-patches] " Vladimir Davydov
2019-04-02 15:49 ` [PATCH v3 2/7] lib: introduce a new json_path_multikey_offset helper Kirill Shcherbatov
2019-04-03 12:56 ` Vladimir Davydov
2019-04-03 16:22 ` [tarantool-patches] " Kirill Shcherbatov
2019-04-03 18:02 ` Vladimir Davydov
2019-04-04 6:17 ` Konstantin Osipov
2019-04-02 15:49 ` [PATCH v3 3/7] box: move offset_slot init to tuple_format_add_field Kirill Shcherbatov
2019-04-03 12:57 ` Vladimir Davydov
2019-04-03 18:02 ` Vladimir Davydov
2019-04-04 6:19 ` [tarantool-patches] " Konstantin Osipov
2019-04-05 17:17 ` [tarantool-patches] " Kirill Shcherbatov
2019-04-02 15:49 ` [PATCH v3 4/7] lib: update msgpuck library Kirill Shcherbatov
2019-04-03 17:49 ` [tarantool-patches] " Kirill Shcherbatov
2019-04-04 15:54 ` Vladimir Davydov
2019-04-05 17:17 ` [tarantool-patches] " Kirill Shcherbatov
2019-04-07 12:22 ` Vladimir Davydov
2019-04-02 15:49 ` [PATCH v3 5/7] box: introduce tuple_parse_iterator class Kirill Shcherbatov
2019-04-03 14:04 ` Vladimir Davydov
2019-04-05 17:17 ` [tarantool-patches] " Kirill Shcherbatov
2019-04-02 15:49 ` [PATCH v3 6/7] box: introduce field_map_builder class Kirill Shcherbatov
2019-04-03 14:38 ` Vladimir Davydov
2019-04-05 17:17 ` [tarantool-patches] " Kirill Shcherbatov
2019-04-03 16:30 ` Vladimir Davydov
2019-04-02 15:49 ` [PATCH v3 7/7] box: introduce multikey indexes in memtx Kirill Shcherbatov
2019-04-04 14:20 ` Vladimir Davydov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7f1136a6-055a-7713-cb6c-91a51a53ec8d@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [tarantool-patches] Re: [PATCH v3 1/7] box: cleanup key_def virtual extract_key setter' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox