From 89d3311aca63ed5d0aa2345f630eb10003bdd9cb Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:24:43 +0100 Subject: Prefer early return in case of error. --- src/modinfodialogconflicts.cpp | 96 +++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 49 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 9dd98751..79ce6ade 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -927,72 +927,70 @@ std::optional AdvancedConflictsTab::createItem( return currOrgId == alt.first; }); - if (currModIter != alternatives.end()) { - isCurrOrigArchive = currModIter->second.first.size() > 0; + if (currModIter == alternatives.end()) { + log::error("Mod {} not found in the list of origins for file {}", currOrigin->getName(), fileName); + return {}; + } + + isCurrOrigArchive = currModIter->second.first.size() > 0; + + if (showAllAlts) { + // fills 'before' and 'after' with all the alternatives that come + // before and after the current mod, trusting the alternatives vector to be + // already sorted correctly - if (showAllAlts) { - // fills 'before' and 'after' with all the alternatives that come - // before and after the current mod, trusting the alternatives vector to be - // already sorted correctly + for (auto iter = alternatives.begin(); iter != alternatives.end(); iter++) { - for (auto iter = alternatives.begin(); iter != alternatives.end(); iter++) { - - const auto& altOrigin = ds.getOriginByID(iter->first); + const auto& altOrigin = ds.getOriginByID(iter->first); - if (iter < currModIter) { - // mod comes before current + if (iter < currModIter) { + // mod comes before current - if (!before.empty()) { - before += L", "; - } - - before += altOrigin.getName(); + if (!before.empty()) { + before += L", "; } - else if (iter > currModIter) { - // mod comes after current - if (!after.empty()) { - after += L", "; - } + before += altOrigin.getName(); + } + else if (iter > currModIter) { + // mod comes after current - after += altOrigin.getName(); + if (!after.empty()) { + after += L", "; } - } - // also add the active winner origin (the one outside alternatives) to 'after' - if (!after.empty()) { - after += L", "; + after += altOrigin.getName(); } - after += ds.getOriginByID(fileOrigin).getName(); - + } + // also add the active winner origin (the one outside alternatives) to 'after' + if (!after.empty()) { + after += L", "; } - else { - // only show nearest origins + after += ds.getOriginByID(fileOrigin).getName(); - // before - if (currModIter > alternatives.begin()) { - auto previousOrigId = (currModIter-1)->first; - before += ds.getOriginByID(previousOrigId).getName(); - } - // after - if (currModIter < (alternatives.end() - 1)) { - auto followingOrigId = (currModIter + 1)->first; - after += ds.getOriginByID(followingOrigId).getName(); - } - else { - // current mod is last of alternatives, so closest to the active winner + } + else { + // only show nearest origins - after += ds.getOriginByID(fileOrigin).getName(); - } - + // before + if (currModIter > alternatives.begin()) { + auto previousOrigId = (currModIter-1)->first; + before += ds.getOriginByID(previousOrigId).getName(); } - } - else { - log::error("Mod {} not found in the list of origins for file {}", currOrigin->getName(), fileName); - return {}; + // after + if (currModIter < (alternatives.end() - 1)) { + auto followingOrigId = (currModIter + 1)->first; + after += ds.getOriginByID(followingOrigId).getName(); + } + else { + // current mod is last of alternatives, so closest to the active winner + + after += ds.getOriginByID(fileOrigin).getName(); + } + } } } -- cgit v1.3.1