From 9460ff26ea5c341fd81c84ec647ba5620e7a3dea Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tsisyk.com> Date: Mon, 4 Sep 2017 15:37:02 +0300 Subject: [PATCH] tuple: extract tuple_format_eq() from vy_stmt.c Needed for #2754 --- src/box/tuple_format.c | 14 ++++++++++++++ src/box/tuple_format.h | 8 ++++++++ src/box/vy_stmt.c | 6 +----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index 9a108077b2..fc6d119182 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -211,6 +211,20 @@ tuple_format_new(struct tuple_format_vtab *vtab, struct key_def **keys, return format; } +bool +tuple_format_eq(const struct tuple_format *a, const struct tuple_format *b) +{ + if (a->field_map_size != b->field_map_size || + a->field_count != b->field_count) + return false; + for (uint32_t i = 0; i < a->field_count; ++i) { + if (a->fields[i].type != b->fields[i].type || + a->fields[i].offset_slot != b->fields[i].offset_slot) + return false; + } + return true; +} + struct tuple_format * tuple_format_dup(const struct tuple_format *src) { diff --git a/src/box/tuple_format.h b/src/box/tuple_format.h index a4a8a467f6..ac84b28a20 100644 --- a/src/box/tuple_format.h +++ b/src/box/tuple_format.h @@ -152,6 +152,14 @@ struct tuple_format * tuple_format_new(struct tuple_format_vtab *vtab, struct key_def **keys, uint16_t key_count, uint16_t extra_size); +/** + * Check that two tuple formats are identical. + * @param a format a + * @param b format b + */ +bool +tuple_format_eq(const struct tuple_format *a, const struct tuple_format *b); + /** * Register the duplicate of the specified format. * @param src Original format. diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c index a22f57b510..01b8cf335b 100644 --- a/src/box/vy_stmt.c +++ b/src/box/vy_stmt.c @@ -325,7 +325,6 @@ vy_stmt_replace_from_upsert(struct tuple_format *replace_format, /* Copy statement data excluding UPSERT operations */ struct tuple_format *format = tuple_format_by_id(upsert->format_id); - (void)format; /* * UPSERT must have the n_upserts field in the extra * memory. @@ -335,10 +334,7 @@ vy_stmt_replace_from_upsert(struct tuple_format *replace_format, * In other fields the REPLACE tuple format must equal to * the UPSERT tuple format. */ - assert(format->field_map_size == replace_format->field_map_size); - assert(format->field_count == replace_format->field_count); - assert(! memcmp(format->fields, replace_format->fields, - sizeof(struct tuple_field_format) * format->field_count)); + assert(tuple_format_eq(format, replace_format)); struct tuple *replace = vy_stmt_alloc(replace_format, bsize); if (replace == NULL) return NULL; -- GitLab