lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 362d02d 1/7: Cache items of wxItemContainer i


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 362d02d 1/7: Cache items of wxItemContainer in MvcController
Date: Thu, 13 Jun 2019 20:39:00 -0400 (EDT)

branch: master
commit 362d02dda5b2970dfe7336951011a6a1a5200cc7
Author: Ilya Sinitsyn <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Cache items of wxItemContainer in MvcController
    
    Store items of itemboxes in MvcController and update the item list only
    when its changed to speed up the ConditionallyEnableItems function.
---
 mvc_controller.cpp | 23 ++++++++++++++++-------
 mvc_controller.hpp |  6 ++++++
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/mvc_controller.cpp b/mvc_controller.cpp
index a3024ff..60329a8 100644
--- a/mvc_controller.cpp
+++ b/mvc_controller.cpp
@@ -331,19 +331,28 @@ void MvcController::ConditionallyEnableItems
         }
     else if(itembox)
         {
-        // WX !! wxWindowUpdateLocker doesn't seem to help much.
-        wxWindowUpdateLocker u(&control);
-        itembox->Clear();
-        // WX !! Append(wxArrayString const&) "may be much faster"
-        // according to wx online help, but that seems untrue: its
-        // implementation just uses a loop.
+        auto& cached_items = itemboxes_cache_[name];
+
+        std::vector<wxString> items;
+        items.reserve(datum->cardinality());
+
         for(int j = 0; j < datum->cardinality(); ++j)
             {
             if(datum->is_allowed(j))
                 {
-                itembox->Append(datum->str(j));
+                items.push_back(datum->str(j));
                 }
             }
+
+        wxWindowUpdateLocker u(&control);
+
+        if(items != cached_items)
+            {
+            std::swap(cached_items, items);
+
+            itembox->Set(cached_items);
+            }
+
         itembox->SetStringSelection(datum->str(datum->ordinal()));
         }
     else
diff --git a/mvc_controller.hpp b/mvc_controller.hpp
index 577e8bc..57c5815 100644
--- a/mvc_controller.hpp
+++ b/mvc_controller.hpp
@@ -30,6 +30,7 @@
 
 #include <map>
 #include <string>
+#include <unordered_map>
 #include <vector>
 
 class MvcModel;
@@ -374,6 +375,9 @@ namespace model_view_controller{} // doxygen workaround.
 ///
 /// view_: Reference to View.
 ///
+/// itemboxes_cache_: Cached items of wxItemContainer instances,
+/// identified by their names, in the View.
+///
 /// last_focused_window_: Points to the last window, other than a
 /// 'Cancel' pushbutton, that had gained focus without losing it
 /// immediately due to UponRefocusInvalidControl(). This is the one
@@ -463,6 +467,8 @@ class MvcController final
     MvcModel& model_;
     MvcView const& view_;
 
+    std::unordered_map<std::string, std::vector<wxString>> itemboxes_cache_;
+
     wxWindow* last_focused_window_;
 
     std::vector<wxWindow*> lineage_;



reply via email to

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