From 360f07e4533d4ede7ba494724382fc8dbcb4649c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 16 Aug 2018 19:10:10 +0200 Subject: Cleanup: pass gasmix by value In a previous commit, the get_gasmix_* functions were changed to return by value. For consistency, also pass gasmix by value. Note that on common 64-bit platforms struct gasmix is the size of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the same space on the stack. On 32-bit platforms, the stack use is probably doubled, but in return a dereference is avoided. Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an invasive change that going back to pointers is probably the least of our worries. This commit is a step in const-ifying input parameters (passing by value is the ultimate way of signaling that the input parameter will not be changed [unless there are references to said parameter]). Signed-off-by: Berthold Stoeger --- profile-widget/tankitem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'profile-widget/tankitem.cpp') diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index d1adae41c..5a8b8ca48 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -57,15 +57,15 @@ void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, str modelDataChanged(); } -void TankItem::createBar(qreal x, qreal w, struct gasmix *gas) +void TankItem::createBar(qreal x, qreal w, struct gasmix gas) { // pick the right gradient, size, position and text QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this); if (gasmix_is_air(gas)) rect->setBrush(air); - else if (gas->he.permille) + else if (gas.he.permille) rect->setBrush(trimix); - else if (gas->o2.permille == 1000) + else if (gas.o2.permille == 1000) rect->setBrush(oxygen); else rect->setBrush(nitrox); @@ -112,14 +112,14 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&) while (ev && (int)ev->time.seconds < last_entry->sec) { width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime); left = hAxis->posAtValue(startTime); - createBar(left, width, &gasmix); + createBar(left, width, gasmix); startTime = ev->time.seconds; gasmix = get_gasmix_from_event(&displayed_dive, ev); ev = get_next_event(ev->next, "gaschange"); } width = hAxis->posAtValue(last_entry->sec) - hAxis->posAtValue(startTime); left = hAxis->posAtValue(startTime); - createBar(left, width, &gasmix); + createBar(left, width, gasmix); } void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal) -- cgit v1.2.3-70-g09d2