Optimize location completion based on profiling
The test was modified slightly because we are not filtering out trailing slahses anymore. We are not quite there still when it comes to treating URIs as we should but for all practical purposes it should be quite a bit faster. The most annoying shortcoming still is that umlauts or any special characters won't match at all.
This commit is contained in:
parent
7470684a3b
commit
43feec8b3d
|
@ -498,23 +498,26 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
||||||
gchar* skey;
|
gchar* skey;
|
||||||
gchar* temp;
|
gchar* temp;
|
||||||
gchar** parts;
|
gchar** parts;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title, -1);
|
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title, -1);
|
||||||
|
|
||||||
desc_uri = desc_title = key = NULL;
|
desc_uri = desc_title = key = NULL;
|
||||||
if (data)
|
if (G_LIKELY (data))
|
||||||
{
|
{
|
||||||
entry = gtk_entry_completion_get_entry (GTK_ENTRY_COMPLETION (data));
|
entry = gtk_entry_completion_get_entry (GTK_ENTRY_COMPLETION (data));
|
||||||
key = g_utf8_strdown (gtk_entry_get_text (GTK_ENTRY (entry)), -1);
|
key = title ? g_utf8_strdown (gtk_entry_get_text (GTK_ENTRY (entry)), -1)
|
||||||
|
: g_ascii_strdown (gtk_entry_get_text (GTK_ENTRY (entry)), -1);
|
||||||
|
len = 0;
|
||||||
}
|
}
|
||||||
if (data && uri)
|
if (G_LIKELY (data && uri))
|
||||||
{
|
{
|
||||||
temp = g_utf8_strdown (uri, -1);
|
temp = g_ascii_strdown (uri, -1);
|
||||||
start = strstr (temp, key);
|
if ((start = strstr (temp, key)))
|
||||||
if (start)
|
|
||||||
{
|
{
|
||||||
skey = g_malloc0 (strlen (key) + 1);
|
len = strlen (key);
|
||||||
g_utf8_strncpy (skey, uri + (start - temp), g_utf8_strlen (key, -1));
|
skey = g_malloc0 (len + 1);
|
||||||
|
strncpy (skey, uri + (start - temp), len);
|
||||||
parts = g_strsplit (uri, skey, 2);
|
parts = g_strsplit (uri, skey, 2);
|
||||||
if (parts && parts[0] && parts[1])
|
if (parts && parts[0] && parts[1])
|
||||||
desc_uri = g_markup_printf_escaped ("%s<b>%s</b>%s",
|
desc_uri = g_markup_printf_escaped ("%s<b>%s</b>%s",
|
||||||
|
@ -526,14 +529,16 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
||||||
}
|
}
|
||||||
if (uri && !desc_uri)
|
if (uri && !desc_uri)
|
||||||
desc_uri = g_markup_escape_text (uri, -1);
|
desc_uri = g_markup_escape_text (uri, -1);
|
||||||
if (data && title)
|
if (G_LIKELY (data && title))
|
||||||
{
|
{
|
||||||
temp = g_utf8_strdown (title, -1);
|
temp = g_utf8_strdown (title, -1);
|
||||||
start = strstr (temp, key);
|
if ((start = strstr (temp, key)))
|
||||||
if (start)
|
|
||||||
{
|
{
|
||||||
skey = g_malloc0 (strlen (key) + 1);
|
size_t utf8_len = g_utf8_strlen (key, -1);
|
||||||
g_utf8_strncpy (skey, title + (start - temp), g_utf8_strlen (key, -1));
|
if (!len)
|
||||||
|
len = strlen (key);
|
||||||
|
skey = g_malloc0 (len + 1);
|
||||||
|
g_utf8_strncpy (skey, title + (start - temp), utf8_len);
|
||||||
parts = g_strsplit (title, skey, 2);
|
parts = g_strsplit (title, skey, 2);
|
||||||
if (parts && parts[0] && parts[1])
|
if (parts && parts[0] && parts[1])
|
||||||
desc_title = g_markup_printf_escaped ("%s<b>%s</b>%s",
|
desc_title = g_markup_printf_escaped ("%s<b>%s</b>%s",
|
||||||
|
@ -547,10 +552,14 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
||||||
desc_title = g_markup_escape_text (title, -1);
|
desc_title = g_markup_escape_text (title, -1);
|
||||||
|
|
||||||
if (desc_title)
|
if (desc_title)
|
||||||
|
{
|
||||||
desc = g_strdup_printf ("%s\n<span color='gray45'>%s</span>",
|
desc = g_strdup_printf ("%s\n<span color='gray45'>%s</span>",
|
||||||
desc_title, desc_uri);
|
desc_title, desc_uri);
|
||||||
|
g_free (desc_uri);
|
||||||
|
g_free (desc_title);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
desc = g_strdup_printf ("%s", desc_uri);
|
desc = desc_uri;
|
||||||
|
|
||||||
g_object_set (renderer, "markup", desc,
|
g_object_set (renderer, "markup", desc,
|
||||||
"ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
"ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
||||||
|
@ -559,8 +568,6 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
||||||
g_free (title);
|
g_free (title);
|
||||||
g_free (key);
|
g_free (key);
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
g_free (desc_uri);
|
|
||||||
g_free (desc_title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -579,14 +586,14 @@ midori_location_entry_completion_match_cb (GtkEntryCompletion* completion,
|
||||||
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title, -1);
|
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title, -1);
|
||||||
|
|
||||||
match = FALSE;
|
match = FALSE;
|
||||||
if (uri)
|
if (G_LIKELY (uri))
|
||||||
{
|
{
|
||||||
temp = g_utf8_casefold (uri, -1);
|
temp = g_utf8_casefold (uri, -1);
|
||||||
match = (strstr (temp, key) != NULL);
|
match = (strstr (temp, key) != NULL);
|
||||||
g_free (temp);
|
g_free (temp);
|
||||||
g_free (uri);
|
g_free (uri);
|
||||||
|
|
||||||
if (!match && title)
|
if (!match && G_LIKELY (title))
|
||||||
{
|
{
|
||||||
temp = g_utf8_casefold (title, -1);
|
temp = g_utf8_casefold (title, -1);
|
||||||
match = (strstr (temp, key) != NULL);
|
match = (strstr (temp, key) != NULL);
|
||||||
|
@ -621,20 +628,6 @@ midori_location_action_set_item (MidoriLocationAction* location_action,
|
||||||
FAVICON_COL, new_icon, -1);
|
FAVICON_COL, new_icon, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar*
|
|
||||||
midori_location_action_format_uri (const gchar* uri)
|
|
||||||
{
|
|
||||||
gchar* new_uri;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
new_uri = g_ascii_strdown (uri, -1);
|
|
||||||
len = strlen (new_uri);
|
|
||||||
|
|
||||||
if (new_uri [len - 1] == '/')
|
|
||||||
new_uri [len - 1] = '\0';
|
|
||||||
return new_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_location_action_iter_lookup:
|
* midori_location_action_iter_lookup:
|
||||||
* @location_action: a #MidoriLocationAction
|
* @location_action: a #MidoriLocationAction
|
||||||
|
@ -653,46 +646,34 @@ midori_location_action_iter_lookup (MidoriLocationAction* location_action,
|
||||||
{
|
{
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
gchar* path;
|
gchar* path;
|
||||||
gchar* new_uri;
|
|
||||||
gchar* tmp_uri;
|
|
||||||
gboolean found;
|
|
||||||
|
|
||||||
model = location_action->model;
|
model = location_action->model;
|
||||||
found = FALSE;
|
|
||||||
|
|
||||||
new_uri = midori_location_action_format_uri (uri);
|
|
||||||
|
|
||||||
if (midori_location_action_is_frozen (location_action))
|
if (midori_location_action_is_frozen (location_action))
|
||||||
{
|
{
|
||||||
if ((path = g_hash_table_lookup (location_action->items, new_uri)))
|
gboolean found = FALSE;
|
||||||
{
|
if ((path = g_hash_table_lookup (location_action->items, uri)))
|
||||||
if (!(found = gtk_tree_model_get_iter_from_string (model, iter, path)))
|
if (!(found = gtk_tree_model_get_iter_from_string (model, iter, path)))
|
||||||
{
|
g_hash_table_remove (location_action->items, uri);
|
||||||
g_hash_table_remove (location_action->items, new_uri);
|
return found;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (gtk_tree_model_get_iter_first (model, iter))
|
if (gtk_tree_model_get_iter_first (model, iter))
|
||||||
{
|
{
|
||||||
tmp_uri = NULL;
|
gchar* tmp_uri = NULL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
gint cmp;
|
||||||
gtk_tree_model_get (model, iter, URI_COL, &tmp_uri, -1);
|
gtk_tree_model_get (model, iter, URI_COL, &tmp_uri, -1);
|
||||||
found = !g_ascii_strncasecmp (new_uri, tmp_uri, strlen (new_uri));
|
cmp = strcmp (uri, tmp_uri);
|
||||||
katze_assign (tmp_uri, NULL);
|
g_free (tmp_uri);
|
||||||
|
if (!cmp)
|
||||||
if (found)
|
return TRUE;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
while (gtk_tree_model_iter_next (model, iter));
|
while (gtk_tree_model_iter_next (model, iter));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
g_free (new_uri);
|
|
||||||
|
|
||||||
return found;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -716,15 +697,13 @@ midori_location_action_iter_insert (MidoriLocationAction* location_action,
|
||||||
if (!midori_location_action_iter_lookup (location_action, uri, iter))
|
if (!midori_location_action_iter_lookup (location_action, uri, iter))
|
||||||
{
|
{
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
gchar* path;
|
|
||||||
gchar* new_uri;
|
|
||||||
|
|
||||||
model = location_action->model;
|
model = location_action->model;
|
||||||
gtk_list_store_insert (GTK_LIST_STORE (model), iter, position);
|
gtk_list_store_insert (GTK_LIST_STORE (model), iter, position);
|
||||||
if (midori_location_action_is_frozen (location_action))
|
if (midori_location_action_is_frozen (location_action))
|
||||||
{
|
{
|
||||||
new_uri = midori_location_action_format_uri (uri);
|
gchar* new_uri = g_strdup (uri);
|
||||||
path = gtk_tree_model_get_string_from_iter (model, iter);
|
gchar* path = gtk_tree_model_get_string_from_iter (model, iter);
|
||||||
g_hash_table_insert (location_action->items, new_uri, path);
|
g_hash_table_insert (location_action->items, new_uri, path);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -28,13 +28,13 @@ static const CompletionItem items[] = {
|
||||||
{ "http://one.com", "One Two" }, /* Duplicate */
|
{ "http://one.com", "One Two" }, /* Duplicate */
|
||||||
{ "http://two.com", "Two" },
|
{ "http://two.com", "Two" },
|
||||||
{ "http://three.com", "Three" },
|
{ "http://three.com", "Three" },
|
||||||
{ "http://one.com/one", "One one" },
|
{ "http://one.com/one/", "One off" },
|
||||||
{ "http://one.com/one/", "One off" }, /* Duplicate */
|
|
||||||
{ "http://four.org", "One" },
|
{ "http://four.org", "One" },
|
||||||
{ "https://four.org", "Four" },
|
{ "https://four.org", "Four" },
|
||||||
{ "ftp://four.org/", "Five" },
|
{ "ftp://four.org/", "Five" },
|
||||||
|
{ "http://muenchen.de/weißwürste/", "Münchner Weißwürste" }, /* Umlauts */
|
||||||
};
|
};
|
||||||
static const guint items_n = 7;
|
static const guint items_n = 9;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
completion_count (void)
|
completion_count (void)
|
||||||
|
@ -94,12 +94,14 @@ static const gchar* tlds[] = {
|
||||||
};
|
};
|
||||||
static const guint tlds_n = 6;
|
static const guint tlds_n = 6;
|
||||||
static const gchar* files[] = {
|
static const gchar* files[] = {
|
||||||
"", "/", "/index.html", "/img.png", "/images", "/images/"/*, "/Images", "/IMAGES"*/
|
"/", "/index.html", "/img.png", /*"/weißwürste",*/ "/images/"
|
||||||
|
/*, "/Images", "/IMAGES/"*/
|
||||||
};
|
};
|
||||||
static const guint files_n = 4; /* 6; */
|
static const guint files_n = 4;
|
||||||
|
|
||||||
static const gchar* inputs[] = {
|
static const gchar* inputs[] = {
|
||||||
"http://www.one.com/index", "http://two.de/images", "http://six.com.au/img"
|
"http://www.one.com/index", "http://two.de/images", "http://six.com.au/img"/*,
|
||||||
|
"http://muenchen.de/weißwürste/"*/
|
||||||
};
|
};
|
||||||
static const gchar* additions[] = {
|
static const gchar* additions[] = {
|
||||||
"http://www.one.com/invention", "http://two.de/island", "http://six.com.au/ish"
|
"http://www.one.com/invention", "http://two.de/island", "http://six.com.au/ish"
|
||||||
|
|
Loading…
Reference in a new issue