dictionary: Short-circuit no-op case in dict_reorder_var().
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 5 Mar 2023 17:23:53 +0000 (09:23 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 5 Mar 2023 19:23:16 +0000 (11:23 -0800)
src/data/dictionary.c

index 2c4633f7f9804b93b87570598481d813fad77488..ebc88b4d9b9765f64306c9a4a2f86644859f3586 100644 (file)
@@ -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);