[Xfce4-commits] <midori:master> Avoid allocations in _action_location_submit_uri

Christian Dywan noreply at xfce.org
Fri Feb 10 23:44:03 CET 2012


Updating branch refs/heads/master
         to 5bb1c5025f8b2170d89a44e4f55d798f7ea671ef (commit)
       from b6f86b0ca61ca567eab7b8493057d38afdc8be1f (commit)

commit 5bb1c5025f8b2170d89a44e4f55d798f7ea671ef
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Feb 10 23:01:50 2012 +0100

    Avoid allocations in _action_location_submit_uri
    
    Skip whitespace without changing the string.
    
    And take advantage of the fact that _find_token now
    can deal with a complete URI.

 katze/katze-utils.c     |   10 ++++++++++
 katze/katze-utils.h     |    3 +++
 midori/midori-browser.c |   35 ++++++++++-------------------------
 3 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/katze/katze-utils.c b/katze/katze-utils.c
index c49d4df..25def2d 100644
--- a/katze/katze-utils.c
+++ b/katze/katze-utils.c
@@ -1190,6 +1190,16 @@ katze_strip_mnemonics (const gchar* original)
   return result;
 }
 
+const gchar*
+katze_skip_whitespace (const gchar* str)
+{
+    if (str == NULL)
+        return NULL;
+    while (*str == ' ' || *str == '\t' || *str == '\n')
+        str++;
+    return str;
+}
+
 /**
  * katze_object_has_property:
  * @object: a #GObject
diff --git a/katze/katze-utils.h b/katze/katze-utils.h
index 643b423..9363776 100644
--- a/katze/katze-utils.h
+++ b/katze/katze-utils.h
@@ -101,6 +101,9 @@ katze_bookmark_populate_tree_view    (KatzeArray* array,
 gchar*
 katze_strip_mnemonics                (const gchar*    original);
 
+const gchar*
+katze_skip_whitespace                (const gchar*    str);
+
 gboolean
 katze_object_has_property            (gpointer     object,
                                       const gchar* property);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 7d0493b..75c2963 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -2305,7 +2305,6 @@ static void
 _action_private_browsing_activate (GtkAction*     action,
                                    MidoriBrowser* browser)
 {
-    const gchar* uri = midori_browser_get_current_uri (browser);
     sokoke_spawn_app ("", TRUE);
 }
 
@@ -3757,44 +3756,34 @@ _action_location_reset_uri (GtkAction*     action,
 }
 
 
-
 static void
 _action_location_submit_uri (GtkAction*     action,
                              const gchar*   uri,
                              gboolean       new_tab,
                              MidoriBrowser* browser)
 {
-    gchar* stripped_uri;
     gchar* new_uri;
     gint n;
 
-    stripped_uri = g_strdup (uri);
-    g_strstrip (stripped_uri);
-    new_uri = sokoke_magic_uri (stripped_uri);
+    uri = katze_skip_whitespace (uri);
+    new_uri = sokoke_magic_uri (uri);
     if (!new_uri)
     {
-        gchar** parts;
-        gchar* keywords = NULL;
+        const gchar* keywords = NULL;
         const gchar* search_uri = NULL;
+        KatzeItem* item;
 
         /* Do we have a keyword and a string? */
-        parts = g_strsplit (stripped_uri, " ", 2);
-        if (parts[0] && browser->search_engines)
+        if (browser->search_engines
+         && (item = katze_array_find_token (browser->search_engines, uri)))
         {
-            KatzeItem* item;
-            if ((item = katze_array_find_token (browser->search_engines, parts[0])))
-            {
-                keywords = g_strdup (parts[1] ? parts[1] : "");
-                search_uri = katze_item_get_uri (item);
-            }
+            keywords = strchr (uri, ' ') + 1;
+            search_uri = katze_item_get_uri (item);
         }
-        g_strfreev (parts);
 
-        if (keywords)
-            g_free (stripped_uri);
-        else
+        if (keywords == NULL)
         {
-            keywords = stripped_uri;
+            keywords = uri;
             search_uri = browser->location_entry_search;
         }
         new_uri = midori_uri_for_search (search_uri, keywords);
@@ -3823,11 +3812,7 @@ _action_location_submit_uri (GtkAction*     action,
             if (sqlite3_step (statement) == SQLITE_DONE)
                 sqlite3_clear_bindings (statement);
         }
-
-        g_free (keywords);
     }
-    else
-        g_free (stripped_uri);
 
     if (new_tab)
     {


More information about the Xfce4-commits mailing list