[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 18f1ca3 7/9: Refactor to remove duplication
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 18f1ca3 7/9: Refactor to remove duplication |
Date: |
Thu, 4 Oct 2018 19:24:15 -0400 (EDT) |
branch: master
commit 18f1ca307120ff02874418411f8b6af5af943956
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Refactor to remove duplication
One function contained an inlined copy of another's code; replaced the
copy with a function call. Incidentally removed type-system acrobatics.
---
ledger.cpp | 20 +++++---------------
1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/ledger.cpp b/ledger.cpp
index 71472be..34beb93 100644
--- a/ledger.cpp
+++ b/ledger.cpp
@@ -170,17 +170,8 @@ void Ledger::SetRunBases(int length)
void Ledger::ZeroInforceAfterLapse()
{
- ledger_map_t const& l_map_rep = ledger_map_->held();
-
- double lapse_year = 0.0;
- for(auto const& i : l_map_rep)
- {
- lapse_year = std::max(lapse_year, i.second.LapseYear);
- }
-
- auto original_length = ledger_invariant_->InforceLives.size();
- using T = decltype(original_length);
- T unlapsed_length = bourn_cast<T>(1 + lapse_year);
+ int original_length = lmi::ssize(ledger_invariant_->InforceLives);
+ int unlapsed_length = 1 + greatest_lapse_dur();
if(unlapsed_length < original_length)
{
ledger_invariant_->InforceLives.resize(unlapsed_length);
@@ -285,13 +276,12 @@ void Ledger::SetOneLedgerVariant
int Ledger::greatest_lapse_dur() const
{
ledger_map_t const& l_map_rep = ledger_map_->held();
- double max_length = 0.0;
-
+ double lapse_dur = 0.0;
for(auto const& i : l_map_rep)
{
- max_length = std::max(max_length, i.second.LapseYear);
+ lapse_dur = std::max(lapse_dur, i.second.LapseYear);
}
- return bourn_cast<int>(max_length);
+ return bourn_cast<int>(lapse_dur);
}
//============================================================================
- [lmi-commits] [lmi] master updated (b3e084f -> b36660c), Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master af5a41d 2/9: Demonstrate the nugatoriness of composite_lapse_year_, Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master b957c49 1/9: Rewrite write_tsv(), Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master 1d9b6e9 4/9: Store a useful value; discard a useless one, Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master 579a4f4 3/9: Simplify [378], Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master fac6d21 8/9: Rename local variables in one function, Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master 4c6e6c3 6/9: Prefer bourn_cast to static_cast for arithmetic type conversions, Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master b36660c 9/9: Define short aliases early; use them wherever possible, Greg Chicares, 2018/10/04
- [lmi-commits] [lmi] master 18f1ca3 7/9: Refactor to remove duplication,
Greg Chicares <=
- [lmi-commits] [lmi] master 797a8b8 5/9: Rename a member function, Greg Chicares, 2018/10/04