From: Ben Pfaff Date: Sun, 5 Mar 2023 17:23:53 +0000 (-0800) Subject: dictionary: Short-circuit no-op case in dict_reorder_var(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66f75a6ba7c0e51f41ddba7b1c82c6e6b5279ed1;p=pspp dictionary: Short-circuit no-op case in dict_reorder_var(). --- 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);