lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master b31583f 2/5: Avoid copying cells when pasting


From: Greg Chicares
Subject: [lmi-commits] [lmi] master b31583f 2/5: Avoid copying cells when pasting into a new census
Date: Tue, 13 Feb 2018 08:02:40 -0500 (EST)

branch: master
commit b31583fe2f9cc15b8a703346fa20726f3cd3b00e
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Avoid copying cells when pasting into a new census
    
    Just swap the new cells with the existing ones to avoid having to
    (temporarily) allocate twice as much memory as we really need.
    
    This results in noticeable reduction to both the memory consumption and
    execution time when pasting a thousand cells.
---
 census_view.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/census_view.cpp b/census_view.cpp
index 1a9cda7..de0ef54 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1763,26 +1763,30 @@ void CensusView::UponPasteCensus(wxCommandEvent&)
         return;
         }
 
+    auto selection = cell_parms().size();
     if(!document().IsModified() && !document().GetDocumentSaved())
         {
         case_parms ().clear();
         case_parms ().push_back(exemplar);
         class_parms().clear();
         class_parms().push_back(exemplar);
-        cell_parms ().clear();
+        cell_parms ().swap(cells);
+
+        selection = 0;
+        }
+    else
+        {
+        cell_parms().reserve(cell_parms().size() + cells.size());
+        std::back_insert_iterator<std::vector<Input>> iip(cell_parms());
+        std::copy(cells.begin(), cells.end(), iip);
         }
 
-    auto selection = cell_parms().size();
-    cell_parms().reserve(cell_parms().size() + cells.size());
-    std::back_insert_iterator<std::vector<Input>> iip(cell_parms());
-    std::copy(cells.begin(), cells.end(), iip);
     document().Modify(true);
     list_model_->Reset(cell_parms().size());
     Update();
     // Reset() leaves the listview unreachable from the keyboard
     // because no row is selected--so select the first added row
     // if possible, else the row after which no row was inserted.
-    selection = std::min(selection, cell_parms().size());
     wxDataViewItem const& z = list_model_->GetItem(selection);
     list_window_->Select(z);
     list_window_->EnsureVisible(z);



reply via email to

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