1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-09 21:54:09 +00:00

refactor: use std::optional.value_or() (#4255)

This commit is contained in:
Charles Kerr 2022-11-27 14:56:34 -06:00 committed by GitHub
parent 33c1098ea0
commit 49393daf01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 10 deletions

View file

@ -968,7 +968,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
s->sizeWhenDone = tor->completion.sizeWhenDone();
auto const verify_progress = tor->verifyProgress();
s->recheckProgress = verify_progress ? *verify_progress : 0.0F;
s->recheckProgress = verify_progress.value_or(0.0);
s->activityDate = tor->activityDate;
s->addedDate = tor->addedDate;
s->doneDate = tor->doneDate;

View file

@ -616,12 +616,7 @@ double tr_truncd(double x, int decimal_places)
pt[decimal_places != 0 ? decimal_places + 1 : 0] = '\0';
}
if (auto parsed = tr_parseNum<double>(std::data(buf)); parsed)
{
return *parsed;
}
return {};
return tr_parseNum<double>(std::data(buf)).value_or(0.0);
}
std::string tr_strpercent(double x)

View file

@ -329,8 +329,7 @@ static void action_callback_POP(
if ((state->special_flags & JSONSL_SPECIALf_NUMNOINT) != 0)
{
auto sv = std::string_view{ jsn->base + state->pos_begin, jsn->pos - state->pos_begin };
auto const val = tr_parseNum<double>(sv);
tr_variantInitReal(get_node(jsn), val ? *val : double{});
tr_variantInitReal(get_node(jsn), tr_parseNum<double>(sv).value_or(0.0));
}
else if ((state->special_flags & JSONSL_SPECIALf_NUMERIC) != 0)
{

View file

@ -87,7 +87,7 @@ void FreeSpaceLabel::onTimer()
// update the tooltip
auto const path = dictFind<QString>(r.args.get(), TR_KEY_path);
setToolTip(QDir::toNativeSeparators(path ? *path : QString()));
setToolTip(QDir::toNativeSeparators(path.value_or(QString{})));
timer_.start();
});