[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 337d81f 37/46: Make UponDeleteCells() more ef
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 337d81f 37/46: Make UponDeleteCells() more efficient for large censuses |
Date: |
Wed, 22 Jul 2020 11:05:16 -0400 (EDT) |
branch: master
commit 337d81ff1d68d0f2ead26102ba5a89ca6ac01565
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Vadim Zeitlin <vadim@tt-solutions.com>
Make UponDeleteCells() more efficient for large censuses
Operate on entire blocks, i.e. ranges of the selected rows, at once,
rather than on the individual rows, as there are many fewer of the
former than of the latter.
---
census_view.cpp | 53 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 33 insertions(+), 20 deletions(-)
diff --git a/census_view.cpp b/census_view.cpp
index c213144..06a7bda 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -2727,13 +2727,33 @@ void CensusDVCView::UponDeleteCells(wxCommandEvent&)
void CensusGridView::UponDeleteCells(wxCommandEvent&)
{
auto const n_items = grid_table_->GetRowsCount();
- auto rows = grid_window_->GetSelectedRows();
- // If no cell is selected then use the current row
- if (rows.empty())
+
+ // Iterate over selected blocks, not rows, as this can be significantly
+ // more efficient: in a grid with 10,000 rows, the user can easily select
+ // all of them, but the selection consists of just a single block, so
+ // iterating over it is quick, while iterating over all the individual rows
+ // would take much longer.
+ auto sel_blocks = grid_window_->GetSelectedRowBlocks();
+
+ int n_sel_items = 0;
+
+ // If no rows are selected, use the current row.
+ if (sel_blocks.empty())
+ {
+ // Synthesize a block corresponding to the current row using 0 for the
+ // column values because we don't use them anyhow.
+ auto const cursor_row = grid_window_->GetGridCursorRow();
+ sel_blocks.push_back(wxGridBlockCoords{cursor_row, 0, cursor_row, 0});
+
+ n_sel_items = 1;
+ }
+ else // Compute the total number of selected rows
{
- rows.push_back(grid_window_->GetGridCursorRow());
+ for(auto const& block : sel_blocks)
+ {
+ n_sel_items += block.GetBottomRow() - block.GetTopRow() + 1;
+ }
}
- auto const n_sel_items = lmi::ssize(rows);
if(n_items == n_sel_items)
{
@@ -2770,33 +2790,26 @@ void CensusGridView::UponDeleteCells(wxCommandEvent&)
auto const cursor_col = grid_window_->GetGridCursorCol();
- std::sort(rows.begin(), rows.end());
-
LMI_ASSERT(lmi::ssize(cell_parms()) == n_items);
wxGridUpdateLocker grid_update_locker(grid_window_);
grid_window_->ClearSelection();
- int items_left = n_sel_items;
- while(items_left > 0)
+ // Annoyingly, range-for can't be used to iterate in the reverse direction
+ // before C++20, so do it manually.
+ for(auto i = sel_blocks.rbegin(); i != sel_blocks.rend(); ++i)
{
- int cur_item = items_left - 1;
- for(; 0 < cur_item; --cur_item)
- {
- if(rows[cur_item] - 1 != rows[cur_item - 1])
- break;
- }
- int const count = items_left - cur_item;
- items_left -= count;
+ auto const& block = *i;
+ auto const count = block.GetBottomRow() - block.GetTopRow() + 1;
- auto const first = cell_parms().begin() + cur_item;
+ auto const first = cell_parms().begin() + block.GetTopRow();
cell_parms().erase(first, first + count);
- grid_window_->DeleteRows(cur_item, count);
+ grid_window_->DeleteRows(block.GetTopRow(), count);
}
LMI_ASSERT(lmi::ssize(cell_parms()) == n_items - n_sel_items);
int const new_cursor_row(std::min
- (rows.front()
+ (sel_blocks.front().GetTopRow()
,lmi::ssize(cell_parms()) - 1
));
grid_window_->GoToCell(new_cursor_row, cursor_col);
- [lmi-commits] [lmi] master b85da3e 24/46: Clarify the comment about CensusViewDataViewModel wrappers, (continued)
- [lmi-commits] [lmi] master b85da3e 24/46: Clarify the comment about CensusViewDataViewModel wrappers, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 5423df7 25/46: Remove separate table_type_converter::type(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master f82b136 31/46: Remove unnecessary make_cell_number_column_read_only() function, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 9f1cb2e 39/46: Only auto-size columns when they change, not after each update, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b3ac65b 43/46: Allow wxGrid to compute census view column sizes more efficiently, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master ece93a0 17/46: Make check for Alt-Enter more obvious in the code, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b57ed4a 18/46: Remove deleted DatumSequenceEditor copy-related methods, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 041ccfc 30/46: Optimize changing grid columns number too, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 53a288a 33/46: Restore "delete_cells" update UI handler for CensusDVCView, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 3c3d0c0 36/46: Explain grid customizations in the function creating it, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 337d81f 37/46: Make UponDeleteCells() more efficient for large censuses,
Greg Chicares <=
- [lmi-commits] [lmi] master 2922db9 44/46: Disallow single cell operations when non-current row is selected, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master d337a22 45/46: Upgrade wx, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master c679655 19/46: Replace table_type_converter::get_all() with register_all(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 7dc508e 35/46: Don't select the first row initially in the grid census view, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 810de0a 26/46: Remove unnecessary wxGrid::IsCellEditControlEnabled() calls, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master adc4089 28/46: Optimize changing grid dimensions when pasting into the census, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master be4c2a4 32/46: Add a comment explaining why the first column is read-only, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b7944ba 38/46: Resize only columns, not rows, in update_visible_columns(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b399a7d 40/46: Remove automatic column auto-sizing in wxGrid-based census view, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master d4ad57b 42/46: Disallow "Edit/Run" cell when multiple grid rows are selected, Greg Chicares, 2020/07/22