Skip to content
Snippets Groups Projects
Commit 2efd9af2 authored by Benedikt Meurer's avatar Benedikt Meurer
Browse files

2005-06-05 Benedikt Meurer <benny@xfce.org>

	* thunar-vfs/thunar-vfs-uri.c: Fix a bug in the thunar_vfs_uri_parent()
	  and thunar_vfs_uri_relative() methods, where the name attribute of
	  the newly created objects wasn't initialized properly.
	* thunar-vfs/thunar-vfs-uri.c(thunar_vfs_uri_equal): Instead of always
	  comparing the full path of both URIs, a simple optimization was
	  introduced, which checks the basenames first, if they are equal,
	  it'll check whether the dirnames have the same length, and as the
	  last fallback, it'll compare the dirnames char by char. This way we
	  can optimize the common case - with GHashTable - that two URIs
	  differ.




(Old svn revision: 16320)
parent 869b97dd
No related branches found
No related tags found
No related merge requests found
2005-06-05 Benedikt Meurer <benny@xfce.org>
* thunar-vfs/thunar-vfs-uri.c: Fix a bug in the thunar_vfs_uri_parent()
and thunar_vfs_uri_relative() methods, where the name attribute of
the newly created objects wasn't initialized properly.
* thunar-vfs/thunar-vfs-uri.c(thunar_vfs_uri_equal): Instead of always
comparing the full path of both URIs, a simple optimization was
introduced, which checks the basenames first, if they are equal,
it'll check whether the dirnames have the same length, and as the
last fallback, it'll compare the dirnames char by char. This way we
can optimize the common case - with GHashTable - that two URIs
differ.
2005-06-05 Benedikt Meurer <benny@xfce.org>
* thunar/thunar-favourites-model.{c,h}: Add new method
......
......@@ -272,15 +272,22 @@ ThunarVfsURI*
thunar_vfs_uri_parent (ThunarVfsURI *uri)
{
ThunarVfsURI *parent;
const gchar *p;
g_return_val_if_fail (THUNAR_VFS_IS_URI (uri), NULL);
if (thunar_vfs_uri_is_root (uri))
return NULL;
/* allocate the new object */
parent = g_object_new (THUNAR_VFS_TYPE_URI, NULL);
parent->path = g_path_get_dirname (uri->path);
/* determine the basename of the path */
for (p = parent->name = parent->path; *p != '\0'; ++p)
if (p[0] == '/' && (p[1] != '/' && p[1] != '\0'))
parent->name = p + 1;
return parent;
}
......@@ -298,13 +305,20 @@ thunar_vfs_uri_relative (ThunarVfsURI *uri,
const gchar *name)
{
ThunarVfsURI *relative;
const gchar *p;
g_return_val_if_fail (THUNAR_VFS_IS_URI (uri), NULL);
g_return_val_if_fail (name != NULL, NULL);
/* allocate the new object */
relative = g_object_new (THUNAR_VFS_TYPE_URI, NULL);
relative->path = g_build_filename (uri->path, name, NULL);
/* determine the basename of the path */
for (p = relative->name = relative->path; *p != '\0'; ++p)
if (p[0] == '/' && (p[1] != '/' && p[1] != '\0'))
relative->name = p + 1;
return relative;
}
......@@ -341,9 +355,42 @@ gboolean
thunar_vfs_uri_equal (gconstpointer a,
gconstpointer b)
{
const gchar *a_name;
const gchar *b_name;
const gchar *a_path;
const gchar *b_path;
const gchar *ap;
const gchar *bp;
g_return_val_if_fail (THUNAR_VFS_IS_URI (a), FALSE);
g_return_val_if_fail (THUNAR_VFS_IS_URI (b), FALSE);
return g_str_equal (THUNAR_VFS_URI (a)->path, THUNAR_VFS_URI (b)->path);
a_name = THUNAR_VFS_URI (a)->name;
b_name = THUNAR_VFS_URI (b)->name;
/* compare the names first */
for (ap = a_name, bp = b_name; *ap == *bp && *ap != '\0'; ++ap, ++bp)
;
if (G_LIKELY (*ap != '\0' || *bp != '\0'))
return FALSE;
a_path = THUNAR_VFS_URI (a)->path;
b_path = THUNAR_VFS_URI (b)->path;
/* check if the dirnames have the same length */
if (G_LIKELY ((a_name - a_path) != (b_name - b_path)))
return FALSE;
/* fallback to a full path comparison (excluding
* the already compared basename)
*/
for (ap = a_path, bp = b_path; *ap == *bp && ap < a_name; ++ap, ++bp)
;
g_assert (ap != a_name || bp == b_name);
g_assert (bp != b_name || ap == a_name);
return (ap == a_name);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment