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.
This commit is contained in:
Christian Dywan 2012-02-10 23:01:50 +01:00
parent b6f86b0ca6
commit 5bb1c5025f
3 changed files with 23 additions and 25 deletions

View file

@ -1190,6 +1190,16 @@ katze_strip_mnemonics (const gchar* original)
return result; 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: * katze_object_has_property:
* @object: a #GObject * @object: a #GObject

View file

@ -101,6 +101,9 @@ katze_bookmark_populate_tree_view (KatzeArray* array,
gchar* gchar*
katze_strip_mnemonics (const gchar* original); katze_strip_mnemonics (const gchar* original);
const gchar*
katze_skip_whitespace (const gchar* str);
gboolean gboolean
katze_object_has_property (gpointer object, katze_object_has_property (gpointer object,
const gchar* property); const gchar* property);

View file

@ -2305,7 +2305,6 @@ static void
_action_private_browsing_activate (GtkAction* action, _action_private_browsing_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
const gchar* uri = midori_browser_get_current_uri (browser);
sokoke_spawn_app ("", TRUE); sokoke_spawn_app ("", TRUE);
} }
@ -3757,44 +3756,34 @@ _action_location_reset_uri (GtkAction* action,
} }
static void static void
_action_location_submit_uri (GtkAction* action, _action_location_submit_uri (GtkAction* action,
const gchar* uri, const gchar* uri,
gboolean new_tab, gboolean new_tab,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
gchar* stripped_uri;
gchar* new_uri; gchar* new_uri;
gint n; gint n;
stripped_uri = g_strdup (uri); uri = katze_skip_whitespace (uri);
g_strstrip (stripped_uri); new_uri = sokoke_magic_uri (uri);
new_uri = sokoke_magic_uri (stripped_uri);
if (!new_uri) if (!new_uri)
{ {
gchar** parts; const gchar* keywords = NULL;
gchar* keywords = NULL;
const gchar* search_uri = NULL; const gchar* search_uri = NULL;
KatzeItem* item;
/* Do we have a keyword and a string? */ /* Do we have a keyword and a string? */
parts = g_strsplit (stripped_uri, " ", 2); if (browser->search_engines
if (parts[0] && browser->search_engines) && (item = katze_array_find_token (browser->search_engines, uri)))
{ {
KatzeItem* item; keywords = strchr (uri, ' ') + 1;
if ((item = katze_array_find_token (browser->search_engines, parts[0]))) search_uri = katze_item_get_uri (item);
{
keywords = g_strdup (parts[1] ? parts[1] : "");
search_uri = katze_item_get_uri (item);
}
} }
g_strfreev (parts);
if (keywords) if (keywords == NULL)
g_free (stripped_uri);
else
{ {
keywords = stripped_uri; keywords = uri;
search_uri = browser->location_entry_search; search_uri = browser->location_entry_search;
} }
new_uri = midori_uri_for_search (search_uri, keywords); 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) if (sqlite3_step (statement) == SQLITE_DONE)
sqlite3_clear_bindings (statement); sqlite3_clear_bindings (statement);
} }
g_free (keywords);
} }
else
g_free (stripped_uri);
if (new_tab) if (new_tab)
{ {