Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH 03/13] tuple: relax struct tuple_update dependency on rope
Date: Tue, 13 Aug 2019 01:05:13 +0200	[thread overview]
Message-ID: <ca681eab7ff760fdc24c559ad554ea1e1fb51c2b.1565649886.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1565649886.git.v.shpilevoy@tarantool.org>

Rope will not be used by tuple_update directly in
next patches.
---
 src/box/tuple_update.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
index 7498d558a..21ea876c9 100644
--- a/src/box/tuple_update.c
+++ b/src/box/tuple_update.c
@@ -820,31 +820,29 @@ update_field_split(struct region *region, struct update_field *prev,
  * @retval  0 Success.
  * @retval -1 Error.
  */
-int
-update_create_rope(struct tuple_update *update, const char *tuple_data,
-		   const char *tuple_data_end, uint32_t field_count)
+struct rope *
+tuple_rope_new(struct region *region, const char *tuple_data,
+	       const char *tuple_data_end, uint32_t field_count)
 {
-	update->rope = rope_new(update->region);
-	if (update->rope == NULL)
-		return -1;
+	struct rope *rope = rope_new(region);
+	if (rope == NULL)
+		return NULL;
 	/* Initialize the rope with the old tuple. */
-
-	struct update_field *first = (struct update_field *)
-			update_alloc(update->region, sizeof(*first));
+	struct update_field *first =
+		(struct update_field *) update_alloc(region, sizeof(*first));
 	if (first == NULL)
-		return -1;
+		return NULL;
 	const char *field = tuple_data;
 	const char *end = tuple_data_end;
 	if (field == end)
-		return 0;
+		return rope;
 
 	/* Add first field to rope */
 	mp_next(&tuple_data);
 	uint32_t field_len = tuple_data - field;
-	update_field_init(first, field, field_len,
-			  end - field - field_len);
+	update_field_init(first, field, field_len, end - field - field_len);
 
-	return rope_append(update->rope, first, field_count);
+	return rope_append(rope, first, field_count) != 0 ? NULL : rope;
 }
 
 static uint32_t
@@ -1119,7 +1117,9 @@ static int
 update_do_ops(struct tuple_update *update, const char *old_data,
 	      const char *old_data_end, uint32_t part_count)
 {
-	if (update_create_rope(update, old_data, old_data_end, part_count) != 0)
+	update->rope = tuple_rope_new(update->region, old_data, old_data_end,
+				      part_count);
+	if (update->rope == NULL)
 		return -1;
 	struct update_op *op = update->ops;
 	struct update_op *ops_end = op + update->op_count;
@@ -1140,7 +1140,9 @@ upsert_do_ops(struct tuple_update *update, const char *old_data,
 	      const char *old_data_end, uint32_t part_count,
 	      bool suppress_error)
 {
-	if (update_create_rope(update, old_data, old_data_end, part_count) != 0)
+	update->rope = tuple_rope_new(update->region, old_data, old_data_end,
+				      part_count);
+	if (update->rope == NULL)
 		return -1;
 	struct update_op *op = update->ops;
 	struct update_op *ops_end = op + update->op_count;
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2019-08-12 23:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 23:05 [tarantool-patches] [PATCH 00/13] JSON updates Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 01/13] tuple: remove alloc and alloc_ctx args from update() Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 10/13] tuple: enable JSON bar updates Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 11/13] tuple: make update operation tokens consumable Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 12/13] tuple: JSON updates support intersection by arrays Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 13/13] tuple: JSON updates support intersection by maps Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 02/13] rope: make rope library macro template Vladislav Shpilevoy
2019-08-12 23:05 ` Vladislav Shpilevoy [this message]
2019-08-12 23:05 ` [tarantool-patches] [PATCH 04/13] int96: add a missing header Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 05/13] tuple: implement update by field name Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 06/13] tuple: expose JSON go_to_key and go_to_index functions Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 07/13] tuple: rework updates to improve code extendibility Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 08/13] json: lexer_eof and token_cmp helper functions Vladislav Shpilevoy
2019-08-12 23:05 ` [tarantool-patches] [PATCH 09/13] tuple: account the whole array in field.data and size Vladislav Shpilevoy
2019-08-20 18:49 ` [tarantool-patches] Re: [PATCH 00/13] JSON updates Vladislav Shpilevoy

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=ca681eab7ff760fdc24c559ad554ea1e1fb51c2b.1565649886.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 03/13] tuple: relax struct tuple_update dependency on rope' \
    /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