lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master a874072 1/3: Fix defect introduced 20081028T0


From: Greg Chicares
Subject: [lmi-commits] [lmi] master a874072 1/3: Fix defect introduced 20081028T0325Z: IRR not calculated when needed
Date: Thu, 15 Feb 2018 22:18:18 -0500 (EST)

branch: master
commit a874072b660bb0f2f33a7eee475f22476559d5a2
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Fix defect introduced 20081028T0325Z: IRR not calculated when needed
    
    For the calculation summary, IRR calculations are skipped if unneeded
    (demonstrably improving responsiveness). They do need to be performed
    later if any IRR is added to the column selection; this was not done
    because of an incorrect conditional. See:
      https://lists.nongnu.org/archive/html/lmi/2018-02/msg00102.html
---
 ledger_text_formats.cpp | 54 +++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/ledger_text_formats.cpp b/ledger_text_formats.cpp
index f82045b..c1f82ff 100644
--- a/ledger_text_formats.cpp
+++ b/ledger_text_formats.cpp
@@ -182,27 +182,41 @@ 
calculation_summary_formatter::calculation_summary_formatter
     columns_.insert(columns_.begin(), "PolicyYear");
 
     unsigned int const length = invar_.GetLength();
-    if(length != invar_.IrrCsvCurrInput.size())
+
+    // TODO ?? This const_cast is safe, but it's still unclean.
+    LedgerInvariant& unclean = const_cast<LedgerInvariant&>(invar_);
+    bool want_any_irr =
+           contains(columns_, "IrrCsv_Current"   )
+        || contains(columns_, "IrrCsv_Guaranteed")
+        || contains(columns_, "IrrDb_Current"    )
+        || contains(columns_, "IrrDb_Guaranteed" )
+        ;
+    // IRRs in the set available in the calculation summary have
+    // not necessarily been calculated: they may be either empty
+    // or filled with a -100% default. This code to test whether
+    // any has not already been calculated is arguably cumbersome
+    // enough to warrant adding an irrs_have_been_calculated flag
+    // to the appropriate ledger class.
+    bool lack_any_irr =
+           invar_.IrrCsvCurrInput.empty()
+        || invar_.IrrCsvGuarInput.empty()
+        || invar_.IrrDbCurrInput .empty()
+        || invar_.IrrDbGuarInput .empty()
+        || each_equal(invar_.IrrCsvCurrInput, -1.0)
+        || each_equal(invar_.IrrCsvGuarInput, -1.0)
+        || each_equal(invar_.IrrDbCurrInput , -1.0)
+        || each_equal(invar_.IrrDbGuarInput , -1.0)
+        ;
+    if(want_any_irr && lack_any_irr && !invar_.IsInforce)
         {
-        // TODO ?? This const_cast is safe, but it's still unclean.
-        LedgerInvariant& unclean = const_cast<LedgerInvariant&>(invar_);
-        bool want_any_irr =
-               contains(columns_, "IrrCsv_Current"   )
-            || contains(columns_, "IrrCsv_Guaranteed")
-            || contains(columns_, "IrrDb_Current"    )
-            || contains(columns_, "IrrDb_Guaranteed" )
-            ;
-        if(want_any_irr && !invar_.IsInforce)
-            {
-            unclean.CalculateIrrs(ledger_);
-            }
-        else
-            {
-            unclean.IrrCsvCurrInput.resize(length, -1.0);
-            unclean.IrrCsvGuarInput.resize(length, -1.0);
-            unclean.IrrDbCurrInput .resize(length, -1.0);
-            unclean.IrrDbGuarInput .resize(length, -1.0);
-            }
+        unclean.CalculateIrrs(ledger_);
+        }
+    else
+        {
+        unclean.IrrCsvCurrInput.resize(length, -1.0);
+        unclean.IrrCsvGuarInput.resize(length, -1.0);
+        unclean.IrrDbCurrInput .resize(length, -1.0);
+        unclean.IrrDbGuarInput .resize(length, -1.0);
         }
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]