[gtk+] fontchooserwidget: Simplify function



commit 824aeb77c60f380f6d90c69c34f5044b11d21d27
Author: Benjamin Otte <otte redhat com>
Date:   Fri Sep 16 10:14:15 2011 +0200

    fontchooserwidget: Simplify function
    
    - Don't do unnecessary casts
    - Fix weird variable declaration indenting
    - Fix loop indentation
    - Use a for loop for iterating over a list, instead of a while loop
    - Casefold font name only once, instead of every iteration
    - Remove needless true_var = true_var && TRUE assignment

 gtk/gtkfontchooserwidget.c |   37 +++++++++++++++----------------------
 1 files changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index af4bda5..c62582b 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -835,16 +835,15 @@ visible_func (GtkTreeModel *model,
               GtkTreeIter  *iter,
               gpointer      user_data)
 {
+  GtkFontChooserWidgetPrivate *priv = user_data;
   gboolean result = TRUE;
-  GtkFontChooserWidgetPrivate *priv = (GtkFontChooserWidgetPrivate*)user_data;
-
-  const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
-  gchar       *font_name;
-  gchar       *term;
-  gchar      **split_terms;
-  gint         n_terms = 0;
+  const gchar *search_text;
+  gchar **split_terms;
+  gchar *font_name, *font_name_casefold, *term_casefold;
+  guint i;
 
   /* If there's no filter string we show the item */
+  search_text = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
   if (strlen (search_text) == 0)
     return TRUE;
 
@@ -856,25 +855,19 @@ visible_func (GtkTreeModel *model,
     return FALSE;
 
   split_terms = g_strsplit (search_text, " ", 0);
-  term = split_terms[0];
-
-  while (term && result)
-  {
-    gchar* font_name_casefold = g_utf8_casefold (font_name, -1);
-    gchar* term_casefold = g_utf8_casefold (term, -1);
+  font_name_casefold = g_utf8_casefold (font_name, -1);
 
-    if (g_strrstr (font_name_casefold, term_casefold))
-      result = result && TRUE;
-    else
-      result = FALSE;
+  for (i = 0; split_terms[i] && result; i++)
+    {
+      gchar* term_casefold = g_utf8_casefold (split_terms[i], -1);
 
-    n_terms++;
-    term = split_terms[n_terms];
+      if (!strstr (font_name_casefold, term_casefold))
+        result = FALSE;
 
-    g_free (term_casefold);
-    g_free (font_name_casefold);
-  }
+      g_free (term_casefold);
+    }
 
+  g_free (font_name_casefold);
   g_free (font_name);
   g_strfreev (split_terms);
 



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