[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_;
- [lmi-commits] [lmi] master updated (e861045 -> 5fce601), Greg Chicares, 2019/06/13
- [lmi-commits] [lmi] master 5fce601 7/7: Correct a typo, Greg Chicares, 2019/06/13
- [lmi-commits] [lmi] master 92bc792 6/7: Add a 'MinPremType' database entity, Greg Chicares, 2019/06/13
- [lmi-commits] [lmi] master f59aa3a 5/7: Add some useful commands, Greg Chicares, 2019/06/13
- [lmi-commits] [lmi] master a729e1a 4/7: Regularize argument order, Greg Chicares, 2019/06/13
- [lmi-commits] [lmi] master 7bc7a7b 3/7: Include standard header for std::swap(), Greg Chicares, 2019/06/13
- [lmi-commits] [lmi] master 362d02d 1/7: Cache items of wxItemContainer in MvcController,
Greg Chicares <=
- [lmi-commits] [lmi] master 9ec7d83 2/7: Update item selection of wxItemContainer only when necessary, Greg Chicares, 2019/06/13