lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 568d6a7 3/5: Reserve memory all at once befor


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 568d6a7 3/5: Reserve memory all at once before appending to 'cells'
Date: Tue, 13 Feb 2018 08:02:40 -0500 (EST)

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

    Reserve memory all at once before appending to 'cells'
    
    Cf. commit b7d99ed of 2018-02-10T22:59:45Z. The status line no longer
    stalls after reading each integral-power-of-two cells.
---
 census_view.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/census_view.cpp b/census_view.cpp
index de0ef54..c8f96e3 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1669,6 +1669,8 @@ void CensusView::UponPasteCensus(wxCommandEvent&)
         ; // Do nothing: neither age nor DOB pasted.
         }
 
+    cells.reserve(std::count(census_data.begin(), census_data.end(), '\n'));
+
     // Read each subsequent line into an input object representing one cell.
     int current_line = 0;
     while(std::getline(iss_census, line, '\n'))
@@ -1764,6 +1766,7 @@ void CensusView::UponPasteCensus(wxCommandEvent&)
         }
 
     auto selection = cell_parms().size();
+
     if(!document().IsModified() && !document().GetDocumentSaved())
         {
         case_parms ().clear();
@@ -1771,7 +1774,6 @@ void CensusView::UponPasteCensus(wxCommandEvent&)
         class_parms().clear();
         class_parms().push_back(exemplar);
         cell_parms ().swap(cells);
-
         selection = 0;
         }
     else



reply via email to

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