[gnome-latex: 54/205] Optimisation of traversals of GList
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 54/205] Optimisation of traversals of GList
- Date: Fri, 14 Dec 2018 10:51:25 +0000 (UTC)
commit aa59030f39f13810ef155a30fddbcce612ebe55a
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Sat Sep 12 00:41:13 2009 +0200
Optimisation of traversals of GList
An other solution would have been to call g_list_foreach ().
src/callbacks.c | 20 ++++++++++++--------
src/prefs.c | 10 ++++++++++
2 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/src/callbacks.c b/src/callbacks.c
index 4b2d0ff..dd081f6 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -739,14 +739,16 @@ cb_line_numbers (GtkToggleButton *toggle_button, gpointer user_data)
gboolean show_line_numbers = gtk_toggle_button_get_active (toggle_button);
latexila.prefs->show_line_numbers = show_line_numbers;
- //TODO optimisation?
- guint nb_docs = g_list_length (latexila.all_docs);
- for (guint i = 0 ; i < nb_docs ; i++)
+ // traverse the list
+ // an other solution is to call g_list_foreach ()
+ GList *current = latexila.all_docs;
+ do
{
- document_t *doc = g_list_nth_data (latexila.all_docs, i);
+ document_t *doc = g_list_nth_data (current, 0);
gtk_source_view_set_show_line_numbers (
GTK_SOURCE_VIEW (doc->source_view), show_line_numbers);
}
+ while ((current = g_list_next (current)) != NULL);
}
void
@@ -959,7 +961,6 @@ create_document_in_new_tab (const gchar *path, const gchar *text, const gchar *t
gtk_widget_show_all (sw);
// add the new document in a new tab
- // TODO set height
GtkWidget *hbox = gtk_hbox_new (FALSE, 3);
GtkWidget *label = gtk_label_new (title);
@@ -1290,12 +1291,15 @@ find_next_match (const gchar *what, GtkSourceSearchFlags flags,
static void
change_font_source_view (void)
{
- guint nb_docs = g_list_length (latexila.all_docs);
- for (guint i = 0 ; i < nb_docs ; i++)
+ // traverse the list
+ // an other solution is to call g_list_foreach ()
+ GList *current = latexila.all_docs;
+ do
{
- document_t *doc = g_list_nth_data (latexila.all_docs, i);
+ document_t *doc = g_list_nth_data (current, 0);
gtk_widget_modify_font (doc->source_view, latexila.prefs->font_desc);
}
+ while ((current = g_list_next (current)) != NULL);
}
static void
diff --git a/src/prefs.c b/src/prefs.c
index a60eeb5..ac57886 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -75,6 +75,7 @@ load_preferences (preferences_t *prefs)
"show_line_numbers", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->show_line_numbers = show_line_numbers_;
g_error_free (error);
error = NULL;
@@ -84,6 +85,7 @@ load_preferences (preferences_t *prefs)
"show_side_pane", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->show_side_pane = show_side_pane_;
g_error_free (error);
error = NULL;
@@ -93,6 +95,7 @@ load_preferences (preferences_t *prefs)
"window_width", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->window_width = window_width_;
g_error_free (error);
error = NULL;
@@ -102,6 +105,7 @@ load_preferences (preferences_t *prefs)
"window_height", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->window_height = window_height_;
g_error_free (error);
error = NULL;
@@ -111,6 +115,7 @@ load_preferences (preferences_t *prefs)
"window_maximised", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->window_maximised = window_maximised_;
g_error_free (error);
error = NULL;
@@ -122,6 +127,7 @@ load_preferences (preferences_t *prefs)
"main_hpaned_pos", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->main_hpaned_pos = main_hpaned_pos_;
g_error_free (error);
error = NULL;
@@ -131,6 +137,7 @@ load_preferences (preferences_t *prefs)
"vpaned_pos", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->vpaned_pos = vpaned_pos_;
g_error_free (error);
error = NULL;
@@ -140,6 +147,7 @@ load_preferences (preferences_t *prefs)
"log_hpaned_pos", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->log_hpaned_pos = log_hpaned_pos_;
g_error_free (error);
error = NULL;
@@ -151,6 +159,7 @@ load_preferences (preferences_t *prefs)
"command_view", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->command_view = g_strdup (command_view_);
g_error_free (error);
error = NULL;
@@ -159,6 +168,7 @@ load_preferences (preferences_t *prefs)
gchar *font = g_key_file_get_string (key_file, PROGRAM_NAME, "font", &error);
if (error != NULL)
{
+ print_warning ("%s", error->message);
prefs->font_str = g_strdup (font_);
set_current_font_prefs (prefs);
g_error_free (error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]