[tarantool-patches] [PATCH 3/4] tuple: update splice should not use index_base after reading args

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun Sep 15 20:32:16 MSK 2019


Splice was the last operation which used index_base in its do_op()
function. Now none of the operations use it. This allows to drop
dependency of operation implementations on index_base and on the
whole tuple_update, in next patches.

Part of #1261
---
 src/box/tuple_update.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/box/tuple_update.c b/src/box/tuple_update.c
index 1b270f2b8..df6308ae2 100644
--- a/src/box/tuple_update.c
+++ b/src/box/tuple_update.c
@@ -457,10 +457,14 @@ static int
 read_arg_splice(int index_base, struct update_op *op,
 		const char **expr)
 {
-	(void) index_base;
 	struct op_splice_arg *arg = &op->arg.splice;
 	if (mp_read_i32(op, expr, &arg->offset) != 0)
 		return -1;
+	if (arg->offset >= 0) {
+		if (arg->offset - index_base < 0)
+			return update_err_splice_bound(op);
+		arg->offset -= index_base;
+	}
 	/* cut length */
 	if (mp_read_i32(op, expr, &arg->cut_length) != 0)
 		return -1;
@@ -755,12 +759,8 @@ do_op_splice(struct tuple_update *update, struct update_op *op)
 		if (-arg->offset > str_len + 1)
 			return update_err_splice_bound(op);
 		arg->offset = arg->offset + str_len + 1;
-	} else if (arg->offset - update->index_base >= 0) {
-		arg->offset -= update->index_base;
-		if (arg->offset > str_len)
-			arg->offset = str_len;
-	} else /* (offset <= 0) */ {
-		return update_err_splice_bound(op);
+	} else if (arg->offset > str_len) {
+		arg->offset = str_len;
 	}
 
 	assert(arg->offset >= 0 && arg->offset <= str_len);
-- 
2.20.1 (Apple Git-117)





More information about the Tarantool-patches mailing list