mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
core: replace same_weightsystem() by operator==()
The important point is that this now takes a reference that avoid string copying. The old code used C-strings and therefore copy-semantics were OK. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
fb3a157462
commit
777e7f32a5
4 changed files with 8 additions and 7 deletions
|
@ -951,7 +951,7 @@ void AddWeight::redo()
|
|||
|
||||
static int find_weightsystem_index(const struct dive *d, const weightsystem_t &ws)
|
||||
{
|
||||
return index_of_if(d->weightsystems, [&ws](auto &ws2) { return same_weightsystem(ws2, ws); });
|
||||
return index_of_if(d->weightsystems, [&ws](auto &ws2) { return ws == ws2; });
|
||||
}
|
||||
|
||||
EditWeightBase::EditWeightBase(int index, bool currentDiveOnly) :
|
||||
|
@ -1047,7 +1047,7 @@ EditWeight::EditWeight(int index, weightsystem_t wsIn, bool currentDiveOnly) :
|
|||
new_ws.description = it->name;
|
||||
|
||||
// If that doesn't change anything, do nothing
|
||||
if (same_weightsystem(ws, new_ws)) {
|
||||
if (ws == new_ws) {
|
||||
dives.clear();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1720,7 +1720,7 @@ static void merge_cylinders(struct dive &res, const struct dive &a, const struct
|
|||
/* Check whether a weightsystem table contains a given weightsystem */
|
||||
static bool has_weightsystem(const weightsystem_table &t, const weightsystem_t &w)
|
||||
{
|
||||
return any_of(t.begin(), t.end(), [&w] (auto &w2) { return same_weightsystem(w, w2); });
|
||||
return any_of(t.begin(), t.end(), [&w] (auto &w2) { return w == w2; });
|
||||
}
|
||||
|
||||
static void merge_equipment(struct dive &res, const struct dive &a, const struct dive &b)
|
||||
|
|
|
@ -172,10 +172,10 @@ void add_cylinder(struct cylinder_table *t, int idx, cylinder_t cyl)
|
|||
t->insert(t->begin() + idx, std::move(cyl));
|
||||
}
|
||||
|
||||
bool same_weightsystem(weightsystem_t w1, weightsystem_t w2)
|
||||
bool weightsystem_t::operator==(const weightsystem_t &w2) const
|
||||
{
|
||||
return w1.weight.grams == w2.weight.grams &&
|
||||
w1.description == w2.description;
|
||||
return std::tie(weight.grams, description) ==
|
||||
std::tie(w2.weight.grams, w2.description);
|
||||
}
|
||||
|
||||
void get_gas_string(struct gasmix gasmix, char *text, int len)
|
||||
|
|
|
@ -60,6 +60,8 @@ struct weightsystem_t
|
|||
weightsystem_t();
|
||||
weightsystem_t(weight_t w, std::string desc, bool auto_filled);
|
||||
~weightsystem_t();
|
||||
|
||||
bool operator==(const weightsystem_t &w2) const;
|
||||
};
|
||||
|
||||
/* Table of weightsystems. Attention: this stores weightsystems,
|
||||
|
@ -72,7 +74,6 @@ extern enum cylinderuse cylinderuse_from_text(const char *text);
|
|||
extern void copy_cylinder_types(const struct dive *s, struct dive *d);
|
||||
extern cylinder_t *add_empty_cylinder(struct cylinder_table *t);
|
||||
extern cylinder_t *get_or_create_cylinder(struct dive *d, int idx);
|
||||
extern bool same_weightsystem(weightsystem_t w1, weightsystem_t w2);
|
||||
extern void remove_cylinder(struct dive *dive, int idx);
|
||||
extern void remove_weightsystem(struct dive *dive, int idx);
|
||||
extern void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws);
|
||||
|
|
Loading…
Reference in a new issue