diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-16 13:35:14 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-23 05:16:38 -0700 |
commit | f5b11daffd6f240268ce78d72c64be43670988ea (patch) | |
tree | 99805cc176483e5f069a7920c11528e37cf0db8c /profile-widget/diveeventitem.cpp | |
parent | b6187f73aad09adb0b70af8d77f1af1a34a338f8 (diff) | |
download | subsurface-f5b11daffd6f240268ce78d72c64be43670988ea.tar.gz |
Cleanup: return gasmix by value
Currently, get_gasmix_from_event() and get_gasmix() return pointers
to either static or to (possibly changing) dive data. This seems like
a dangerous practice and the returned data should be used immediately.
Instead, return the gasmix by value. This is in preparation of
const-ifying input parameters of a number of core functions, which
will ultimately let the merge() function take const-arguments in
preparation of undo of dive-merging.
On common 64-bit systems gasmix (two "int"s) is the size of a pointer
and can be returned in a register.
On 32-bit systems a pointer to the struct to be filled out will be
passed.
Since get_gasmix() now returns a value, the first invocation is
tested by a NULL-initialized "struct event *". Document this in
a comment.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/diveeventitem.cpp')
-rw-r--r-- | profile-widget/diveeventitem.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 13ab3770b..875954b37 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -92,20 +92,20 @@ void DiveEventItem::setupPixmap(struct gasmix *lastgasmix) } else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) { setPixmap(EVENT_PIXMAP(":dive-bookmark-icon")); } else if (event_is_gaschange(internalEvent)) { - struct gasmix *mix = get_gasmix_from_event(&displayed_dive, internalEvent); + struct gasmix mix = get_gasmix_from_event(&displayed_dive, internalEvent); struct icd_data icd_data; - bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data); - if (mix->he.permille) { + bool icd = isobaric_counterdiffusion(lastgasmix, &mix, &icd_data); + if (mix.he.permille) { if (icd) setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-trimix-ICD-icon")); else setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-trimix-icon")); - } else if (gasmix_is_air(mix)) { + } else if (gasmix_is_air(&mix)) { if (icd) setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-air-ICD-icon")); else setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-air-icon")); - } else if (mix->o2.permille == 1000) { + } else if (mix.o2.permille == 1000) { if (icd) setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-oxygen-ICD-icon")); else @@ -174,15 +174,15 @@ void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix) if (event_is_gaschange(internalEvent)) { struct icd_data icd_data; - struct gasmix *mix = get_gasmix_from_event(&displayed_dive, internalEvent); + struct gasmix mix = get_gasmix_from_event(&displayed_dive, internalEvent); struct membuffer mb = {}; name += ": "; - name += gasname(mix); + name += gasname(&mix); /* Do we have an explicit cylinder index? Show it. */ if (internalEvent->gas.index >= 0) name += tr(" (cyl. %1)").arg(internalEvent->gas.index + 1); - bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data); + bool icd = isobaric_counterdiffusion(lastgasmix, &mix, &icd_data); if (icd_data.dHe < 0) { put_format(&mb, "\n%s %s:%+.3g%% %s:%+.3g%%%s%+.3g%%", qPrintable(tr("ICD")), @@ -192,7 +192,7 @@ void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix) name += QString::fromUtf8(mb.buffer, mb.len); free_buffer(&mb); } - *lastgasmix = *mix; + *lastgasmix = mix; } else if (same_string(internalEvent->name, "modechange")) { name += QString(": %1").arg(gettextFromC::tr(divemode_text_ui[internalEvent->value])); } else if (value) { |