Optimize sokoke_magic_uri for better performance
This commit is contained in:
parent
5be54230af
commit
3ecfecb555
1 changed files with 35 additions and 40 deletions
|
@ -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,12 +235,12 @@ 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? */
|
/* Do we have a domain, ip address or localhost? */
|
||||||
search = strchr (uri, ':');
|
if ((search = strchr (uri, ':')) && search[0] &&
|
||||||
if (search && search[0] &&
|
|
||||||
!g_ascii_isalpha (search[1]) && search[1] != ' ')
|
!g_ascii_isalpha (search[1]) && search[1] != ' ')
|
||||||
if (!strchr (search, '.'))
|
if (!strchr (search, '.'))
|
||||||
return sokoke_idn_to_punycode (g_strconcat ("http://", uri, NULL));
|
return sokoke_idn_to_punycode (g_strconcat ("http://", uri, NULL));
|
||||||
|
@ -249,14 +249,15 @@ sokoke_magic_uri (const gchar* uri,
|
||||||
parts = g_strsplit (uri, ".", 0);
|
parts = g_strsplit (uri, ".", 0);
|
||||||
if (!search && parts[0] && parts[1])
|
if (!search && parts[0] && parts[1])
|
||||||
{
|
{
|
||||||
search = NULL;
|
|
||||||
if (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0])))
|
if (!(parts[1][1] == '\0' && !g_ascii_isalpha (parts[1][0])))
|
||||||
if (!strchr (parts[0], ' ') && !strchr (parts[1], ' '))
|
if (!strchr (parts[0], ' ') && !strchr (parts[1], ' '))
|
||||||
search = g_strconcat ("http://", uri, NULL);
|
if ((search = g_strconcat ("http://", uri, NULL)))
|
||||||
g_free (parts);
|
{
|
||||||
if (search)
|
g_strfreev (parts);
|
||||||
return sokoke_idn_to_punycode (search);
|
return sokoke_idn_to_punycode (search);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
g_strfreev (parts);
|
||||||
/* We don't want to search? So return early. */
|
/* We don't want to search? So return early. */
|
||||||
if (!search_engines)
|
if (!search_engines)
|
||||||
return g_strdup (uri);
|
return g_strdup (uri);
|
||||||
|
@ -265,22 +266,16 @@ sokoke_magic_uri (const gchar* uri,
|
||||||
/* Do we have a keyword and a string? */
|
/* Do we have a keyword and a string? */
|
||||||
parts = g_strsplit (uri, " ", 2);
|
parts = g_strsplit (uri, " ", 2);
|
||||||
if (parts[0] && parts[1])
|
if (parts[0] && parts[1])
|
||||||
|
if ((item = katze_array_find_token (search_engines, parts[0])))
|
||||||
{
|
{
|
||||||
item = katze_array_find_token (search_engines, parts[0]);
|
|
||||||
if (item)
|
|
||||||
search_uri = katze_item_get_uri (item);
|
search_uri = katze_item_get_uri (item);
|
||||||
}
|
|
||||||
g_free (parts);
|
|
||||||
if (search_uri)
|
|
||||||
{
|
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
g_strfreev (parts);
|
||||||
return search;
|
return search;
|
||||||
}
|
|
||||||
return sokoke_idn_to_punycode (g_strdup (uri));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue