gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Fri Mar 18 19:14:18 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/5388cc8e (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e0db8790 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4eec093a (commit)
	from  https://github.com/Gnucash/gnucash/commit/4bb16f03 (commit)



commit 5388cc8e2c3494c9d813bcdf969798ae864f5534
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Mar 18 11:04:11 2022 +0800

    [kvp-frame.cpp] minor speedups
    
    reserve vector, cache iterator from m_valuemap.find for reuse
    immediately afterwards.

diff --git a/libgnucash/engine/kvp-frame.cpp b/libgnucash/engine/kvp-frame.cpp
index 6ab5bc5a6..74d33b8fa 100644
--- a/libgnucash/engine/kvp-frame.cpp
+++ b/libgnucash/engine/kvp-frame.cpp
@@ -74,9 +74,10 @@ KvpFrame::get_child_frame_or_nullptr (Path const & path) noexcept
     if (!path.size ())
         return this;
     auto key = path.front ();
-    if (m_valuemap.find (key.c_str ()) == m_valuemap.end ())
+    auto map_iter = m_valuemap.find (key.c_str ());
+    if (map_iter == m_valuemap.end ())
         return nullptr;
-    auto child = m_valuemap.at (key.c_str ())->get <KvpFrame *> ();
+    auto child = map_iter->second->get <KvpFrame *> ();
     Path send;
     std::copy (path.begin () + 1, path.end (), std::back_inserter (send));
     return child->get_child_frame_or_nullptr (send);
@@ -190,6 +191,7 @@ std::vector<std::string>
 KvpFrameImpl::get_keys() const noexcept
 {
     std::vector<std::string> ret;
+    ret.reserve (m_valuemap.size());
     std::for_each(m_valuemap.begin(), m_valuemap.end(),
         [&ret](const KvpFrameImpl::map_type::value_type &a)
         {

commit e0db8790afe68a2efe97dfe11b0671a0e2214e0c
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Mar 17 00:29:24 2022 +0800

    [reconcile-view.c] prepend & reverse

diff --git a/gnucash/gnome/reconcile-view.c b/gnucash/gnome/reconcile-view.c
index 8d1a9bafd..be62488c9 100644
--- a/gnucash/gnome/reconcile-view.c
+++ b/gnucash/gnome/reconcile-view.c
@@ -690,10 +690,11 @@ gnc_reconcile_view_set_list (GNCReconcileView  *view, gboolean reconcile)
     for (node = list_of_rows; node; node = node->next)
     {
         GtkTreeRowReference *rowref = gtk_tree_row_reference_new (model, node->data);
-        rr_list = g_list_append (rr_list, rowref);
+        rr_list = g_list_prepend (rr_list, rowref);
         gtk_tree_path_free (node->data);
     }
 
+    rr_list = g_list_reverse (rr_list);
     for (node = rr_list; node; node = node->next)
     {
         GtkTreeIter          iter;

commit 4eec093accdc1a00142e3f83e8c42099cc915c8f
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Mar 16 21:44:30 2022 +0800

    use gtk_tree_view_get_n_columns
    
    instead of g_list_length (gtk_tree_view_get_columns (tree))

diff --git a/gnucash/gnome-utils/gnc-tree-view.c b/gnucash/gnome-utils/gnc-tree-view.c
index babe8dc67..977323704 100644
--- a/gnucash/gnome-utils/gnc-tree-view.c
+++ b/gnucash/gnome-utils/gnc-tree-view.c
@@ -2154,13 +2154,7 @@ gint
 gnc_tree_view_append_column (GncTreeView *view,
                              GtkTreeViewColumn *column)
 {
-    GList *columns;
-    int n;
-
-    /* There's no easy way to get this number. */
-    columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(view));
-    n = g_list_length (columns);
-    g_list_free (columns);
+    int n = gtk_tree_view_get_n_columns (GTK_TREE_VIEW(view));
 
     /* Ignore the initial column, the selection menu */
     if (n >= 1)
@@ -2177,7 +2171,7 @@ get_column_next_to (GtkTreeView *tv, GtkTreeViewColumn **col, gboolean backward)
     gboolean wrapped = FALSE;
 
     cols = gtk_tree_view_get_columns (tv);
-    g_return_val_if_fail (g_list_length (cols) > 0, FALSE);
+    g_return_val_if_fail (cols != NULL, FALSE);
 
     node = g_list_find (cols, *col);
     g_return_val_if_fail (node, FALSE);
diff --git a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
index 1b1410d6e..15c24dd1c 100644
--- a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
+++ b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
@@ -1646,9 +1646,7 @@ void CsvImpPriceAssist::preview_refresh_table ()
 
     /* Start with counting the current number of columns (ntcols)
      * we have in the treeview */
-    auto columns = gtk_tree_view_get_columns (treeview);
-    auto ntcols = g_list_length(columns);
-    g_list_free (columns);
+    auto ntcols = gtk_tree_view_get_n_columns (treeview);
 
     /* Drop redundant columns if the model has less data columns than the new model
      * ntcols = n° of columns in treeview (1 error column + x data columns)
diff --git a/gnucash/import-export/csv-imp/assistant-csv-trans-import.cpp b/gnucash/import-export/csv-imp/assistant-csv-trans-import.cpp
index 7328e89ca..07d1cb1d0 100644
--- a/gnucash/import-export/csv-imp/assistant-csv-trans-import.cpp
+++ b/gnucash/import-export/csv-imp/assistant-csv-trans-import.cpp
@@ -1572,9 +1572,7 @@ void CsvImpTransAssist::preview_refresh_table ()
 
     /* Start with counting the current number of columns (ntcols)
      * we have in the treeview */
-    auto columns = gtk_tree_view_get_columns (treeview);
-    auto ntcols = g_list_length(columns);
-    g_list_free (columns);
+    auto ntcols = gtk_tree_view_get_n_columns (treeview);
 
     /* Drop redundant columns if the model has less data columns than the new model
      * ntcols = n° of columns in treeview (1 error column + x data columns)



Summary of changes:
 gnucash/gnome-utils/gnc-tree-view.c                          | 10 ++--------
 gnucash/gnome/reconcile-view.c                               |  3 ++-
 gnucash/import-export/csv-imp/assistant-csv-price-import.cpp |  4 +---
 gnucash/import-export/csv-imp/assistant-csv-trans-import.cpp |  4 +---
 libgnucash/engine/kvp-frame.cpp                              |  6 ++++--
 5 files changed, 10 insertions(+), 17 deletions(-)



More information about the gnucash-changes mailing list