From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org,
Alexander Turenko <alexander.turenko@tarantool.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: Re: [tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module
Date: Thu, 28 Mar 2019 10:38:41 +0300 [thread overview]
Message-ID: <8666d4a1-43da-78f3-c8ab-538fbf4d8893@tarantool.org> (raw)
In-Reply-To: <20190328020146.lluz4mg5tacpghwv@tkn_work_nb>
> Consider the case when a user get tuples from a local space (or merger)
> and they have a format that allows to compare faster using precalculated
> offsets. I think we should not create a new tuple(s) in the case.
>
> Applicable for other functions too.
If we decide to support setting arguments in the form of tables, I propose to
introduce the following function. In my opinion, it does not look unnatural.
diff --git a/src/box/lua/key_def.c b/src/box/lua/key_def.c
index 18d5d961d..9cacf3cca 100644
--- a/src/box/lua/key_def.c
+++ b/src/box/lua/key_def.c
@@ -224,6 +224,23 @@ lbox_key_def_gc(struct lua_State *L)
return 0;
}
+/**
+ * Take existent tuple from LUA stack or build a new tuple with
+ * default format from table, check for compatibility with a
+ * given key_def.
+ */
+static struct tuple *
+lbox_key_def_check_tuple(struct lua_State *L, struct key_def *key_def, int idx)
+{
+ struct tuple *tuple = luaT_istuple(L, idx);
+ if (tuple == NULL)
+ tuple = luaT_tuple_new(L, 2, box_tuple_format_default());
+ if (tuple == NULL || tuple_validate_parts(key_def, tuple) != 0)
+ return NULL;
+ tuple_ref(tuple);
+ return tuple;
+}
+
static int
lbox_key_def_extract_key(struct lua_State *L)
{
@@ -231,12 +248,9 @@ lbox_key_def_extract_key(struct lua_State *L)
if (lua_gettop(L) != 2 || (key_def = check_key_def(L, 1)) == NULL)
return luaL_error(L, "Usage: key_def:extract_key(tuple)");
- struct tuple_format *format = box_tuple_format_default();
struct tuple *tuple;
- if ((tuple = luaT_tuple_new(L, 2, format)) == NULL ||
- tuple_validate_parts(key_def, tuple) != 0)
+ if ((tuple = lbox_key_def_check_tuple(L, key_def, 2)) == NULL)
return luaT_error(L);
- tuple_ref(tuple);
uint32_t key_size;
char *key = tuple_extract_key(tuple, key_def, &key_size);
@@ -244,7 +258,8 @@ lbox_key_def_extract_key(struct lua_State *L)
if (key == NULL)
return luaT_error(L);
- struct tuple *ret = box_tuple_new(format, key, key + key_size);
+ struct tuple *ret =
+ box_tuple_new(box_tuple_format_default(), key, key + key_size);
if (ret == NULL)
return luaT_error(L);
luaT_pushtuple(L, ret);
@@ -261,17 +276,12 @@ lbox_key_def_compare(struct lua_State *L)
}
struct tuple *tuple_a, *tuple_b;
- struct tuple_format *format = box_tuple_format_default();
- if ((tuple_a = luaT_tuple_new(L, 2, format)) == NULL ||
- tuple_validate_parts(key_def, tuple_a) != 0)
+ if ((tuple_a = lbox_key_def_check_tuple(L, key_def, 2)) == NULL)
return luaT_error(L);
- tuple_ref(tuple_a);
- if ((tuple_b = luaT_tuple_new(L, 3, format)) == NULL ||
- tuple_validate_parts(key_def, tuple_b) != 0) {
+ if ((tuple_b = lbox_key_def_check_tuple(L, key_def, 3)) == NULL) {
tuple_unref(tuple_a);
return luaT_error(L);
}
- tuple_ref(tuple_b);
int rc = tuple_compare(tuple_a, tuple_b, key_def);
tuple_unref(tuple_a);
@@ -291,10 +301,8 @@ lbox_key_def_compare_with_key(struct lua_State *L)
struct tuple *tuple, *key_tuple = NULL;
struct tuple_format *format = box_tuple_format_default();
- if ((tuple = luaT_tuple_new(L, 2, format)) == NULL ||
- tuple_validate_parts(key_def, tuple) != 0)
+ if ((tuple = lbox_key_def_check_tuple(L, key_def, 2)) == NULL)
return luaT_error(L);
- tuple_ref(tuple);
if ((key_tuple = luaT_tuple_new(L, 3, format)) == NULL) {
tuple_unref(tuple);
return luaT_error(L);
next prev parent reply other threads:[~2019-03-28 7:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 14:29 [tarantool-patches] [PATCH v2 0/2] " Kirill Shcherbatov
2019-03-27 14:29 ` [tarantool-patches] [PATCH v2 1/2] lua: add luaT_tuple_new() Kirill Shcherbatov
2019-03-28 9:01 ` [tarantool-patches] " Konstantin Osipov
2019-03-28 9:18 ` Alexander Turenko
2019-04-03 18:01 ` [tarantool-patches] " Vladimir Davydov
2019-04-04 2:51 ` Alexander Turenko
2019-04-04 8:14 ` Vladimir Davydov
2019-03-27 14:29 ` [tarantool-patches] [PATCH v2 2/2] lua: add key_def lua module Kirill Shcherbatov
2019-03-28 2:01 ` Alexander Turenko
2019-03-28 7:38 ` Kirill Shcherbatov [this message]
2019-03-28 8:41 ` [tarantool-patches] " Kirill Shcherbatov
[not found] ` <6d915212-e80f-4a6d-d884-b838bf25f8a7@tarantool.org>
2019-03-28 11:22 ` Alexander Turenko
2019-04-03 11:10 ` Vladimir Davydov
2019-04-03 11:46 ` Alexander Turenko
2019-04-03 12:01 ` Vladimir Davydov
2019-04-03 13:26 ` Alexander Turenko
2019-04-04 5:07 ` Alexander Turenko
2019-04-04 8:04 ` Kirill Shcherbatov
2019-04-04 9:05 ` Vladimir Davydov
2019-04-04 11:46 ` Alexander Turenko
2019-04-04 14:36 ` Vladimir Davydov
2019-04-04 8:38 ` Vladimir Davydov
2019-04-04 11:17 ` Alexander Turenko
2019-04-04 12:00 ` Alexander Turenko
2019-04-04 14:42 ` 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=8666d4a1-43da-78f3-c8ab-538fbf4d8893@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=alexander.turenko@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module' \
/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