diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-11-24 10:01:03 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-09 20:58:04 -0800 |
commit | 2802d4296960eb6ad76292baa105075c5427ea67 (patch) | |
tree | 45e96ec24c73bc350c767a9bc22c42152d41874d /core/divelist.c | |
parent | 825fcc854788750d0d1afc4a6d1cdae9e85e738e (diff) | |
download | subsurface-2802d4296960eb6ad76292baa105075c5427ea67.tar.gz |
Cleanup: Make add_dive_to_table local to divelist.c
This function was not used outside of divelist.c, therefore make it
local. Moreover rename it to add_to_divetable so that the name
is generic and can be generated by a macro.
Moreover, remove the special case idx = -1, which would determine
the insertion index. Instead let the single caller who used this
feature do this.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divelist.c')
-rw-r--r-- | core/divelist.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/core/divelist.c b/core/divelist.c index 320713bc7..c25a29c16 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -29,7 +29,6 @@ * dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b) * struct dive *unregister_dive(int idx) * void delete_single_dive(int idx) - * void add_dive_to_table(struct dive_table *table, int idx, struct dive *dive) * void add_single_dive(int idx, struct dive *dive) * void select_dive(struct dive *dive) * void deselect_dive(struct dive *dive) @@ -872,6 +871,20 @@ struct dive *last_selected_dive() return ret; } +/* add a dive at the given index to a dive table. */ +static void add_to_dive_table(struct dive_table *table, int idx, struct dive *dive) +{ + int i; + grow_dive_table(table); + table->nr++; + + for (i = idx; i < table->nr; i++) { + struct dive *tmp = table->dives[i]; + table->dives[i] = dive; + dive = tmp; + } +} + static void unregister_dive_from_table(struct dive_table *table, int idx) { int i; @@ -910,11 +923,13 @@ void remove_dive_from_trip(struct dive *dive) * from trip beforehand. */ void add_dive_to_trip(struct dive *dive, dive_trip_t *trip) { + int idx; if (dive->divetrip == trip) return; if (dive->divetrip) fprintf(stderr, "Warning: adding dive to trip that has trip set\n"); - add_dive_to_table(&trip->dives, -1, dive); + idx = dive_get_insertion_index(&trip->dives, dive); + add_to_dive_table(&trip->dives, idx, dive); dive->divetrip = trip; } @@ -1131,29 +1146,12 @@ int dive_get_insertion_index(struct dive_table *table, struct dive *dive) return table->nr; } -/* add a dive at the given index to a dive table. if the index is negative, - * the dive will be added according to dive_less_than() order */ -void add_dive_to_table(struct dive_table *table, int idx, struct dive *dive) -{ - int i; - if (idx < 0) - idx = dive_get_insertion_index(table, dive); - grow_dive_table(table); - table->nr++; - - for (i = idx; i < table->nr; i++) { - struct dive *tmp = table->dives[i]; - table->dives[i] = dive; - dive = tmp; - } -} - /* add a dive at the given index in the global dive table and keep track * of the number of selected dives. if the index is negative, the dive will * be added according to dive_less_than() order */ void add_single_dive(int idx, struct dive *dive) { - add_dive_to_table(&dive_table, idx, dive); + add_to_dive_table(&dive_table, idx, dive); if (dive->selected) amount_selected++; } |