From 66f75a6ba7c0e51f41ddba7b1c82c6e6b5279ed1 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 5 Mar 2023 09:23:53 -0800 Subject: [PATCH] dictionary: Short-circuit no-op case in dict_reorder_var(). --- src/data/dictionary.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 2c4633f7f9..ebc88b4d9b 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -950,10 +950,12 @@ dict_contains_var (const struct dictionary *d, const struct variable *v) void dict_reorder_var (struct dictionary *d, struct variable *v, size_t new_index) { - size_t old_index = var_get_dict_index (v); - assert (new_index < d->n_vars); + size_t old_index = var_get_dict_index (v); + if (new_index == old_index) + return; + unindex_vars (d, MIN (old_index, new_index), MAX (old_index, new_index) + 1); move_element (d->vars, d->n_vars, sizeof *d->vars, old_index, new_index); reindex_vars (d, MIN (old_index, new_index), MAX (old_index, new_index) + 1, false); -- 2.30.2