Optimize sokoke_magic_uri for better performance

This commit is contained in:
Christian Dywan 2009-03-31 03:28:01 +02:00
parent 5be54230af
commit 3ecfecb555

View file

@ -189,7 +189,7 @@ sokoke_idn_to_punycode (gchar* uri)
if (proto) if (proto)
{ {
result = g_strdup_printf ("%s://%s%s", proto, s, path ? path : ""); result = g_strconcat (proto, "://", s, path ? path : "", NULL);
g_free (proto); g_free (proto);
if (path) if (path)
g_free (hostname); g_free (hostname);
@ -235,52 +235,47 @@ sokoke_magic_uri (const gchar* uri,
g_free (current_dir); g_free (current_dir);
return result; return result;
} }
/* Do we need to add a protocol? */ /* Do we have a protocol? */
if (!strstr (uri, "://")) if (g_strstr_len (uri, 8, "://"))
return sokoke_idn_to_punycode (g_strdup (uri));
/* Do we have a domain, ip address or localhost? */
if ((search = strchr (uri, ':')) && search[0] &&
!g_ascii_isalpha (search[1]) && search[1] != ' ')
if (!strchr (search, '.'))
return sokoke_idn_to_punycode (g_strconcat ("http://", uri, NULL));
if (!strcmp (uri, "localhost") || g_str_has_prefix (uri, "localhost/"))
return g_strconcat ("http://", uri, NULL);
parts = g_strsplit (uri, ".", 0);
if (!search && parts[0] && parts[1])
{ {
/* Do we have a domain, ip address or localhost? */ if (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0])))
search = strchr (uri, ':'); if (!strchr (parts[0], ' ') && !strchr (parts[1], ' '))
if (search && search[0] && if ((search = g_strconcat ("http://", uri, NULL)))
!g_ascii_isalpha (search[1]) && search[1] != ' ') {
if (!strchr (search, '.')) g_strfreev (parts);
return sokoke_idn_to_punycode (g_strconcat ("http://", uri, NULL)); return sokoke_idn_to_punycode (search);
if (!strcmp (uri, "localhost") || g_str_has_prefix (uri, "localhost/")) }
return g_strconcat ("http://", uri, NULL); }
parts = g_strsplit (uri, ".", 0); g_strfreev (parts);
if (!search && parts[0] && parts[1]) /* We don't want to search? So return early. */
{ if (!search_engines)
search = NULL; return g_strdup (uri);
if (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0]))) search = NULL;
if (!strchr (parts[0], ' ') && !strchr (parts[1], ' ')) search_uri = NULL;
search = g_strconcat ("http://", uri, NULL); /* Do we have a keyword and a string? */
g_free (parts); parts = g_strsplit (uri, " ", 2);
if (search) if (parts[0] && parts[1])
return sokoke_idn_to_punycode (search); if ((item = katze_array_find_token (search_engines, parts[0])))
}
/* We don't want to search? So return early. */
if (!search_engines)
return g_strdup (uri);
search = NULL;
search_uri = NULL;
/* Do we have a keyword and a string? */
parts = g_strsplit (uri, " ", 2);
if (parts[0] && parts[1])
{
item = katze_array_find_token (search_engines, parts[0]);
if (item)
search_uri = katze_item_get_uri (item);
}
g_free (parts);
if (search_uri)
{ {
search_uri = katze_item_get_uri (item);
if (strstr (search_uri, "%s")) if (strstr (search_uri, "%s"))
search = g_strdup_printf (search_uri, parts[1]); search = g_strdup_printf (search_uri, parts[1]);
else else
search = g_strdup_printf ("%s%s", search_uri, parts[1]); search = g_strdup_printf ("%s%s", search_uri, parts[1]);
} }
return search; g_strfreev (parts);
} return search;
return sokoke_idn_to_punycode (g_strdup (uri));
} }
void void