mirror of https://github.com/MidnightCommander/mc
VFS: internal changes in vfs_path_t type.
Changed type of array from slower GList to faster GArray. Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
902e5cb978
commit
78f9f4252e
|
@ -385,7 +385,7 @@ vfs_path_from_str_deprecated_parser (char *path)
|
|||
if (*op != '\0')
|
||||
element->vfs_prefix = g_strdup (op);
|
||||
|
||||
vpath->path = g_list_prepend (vpath->path, element);
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
}
|
||||
if (path[0] != '\0')
|
||||
{
|
||||
|
@ -396,7 +396,7 @@ vfs_path_from_str_deprecated_parser (char *path)
|
|||
element->encoding = vfs_get_encoding (path);
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
vpath->path = g_list_prepend (vpath->path, element);
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
}
|
||||
|
||||
return vpath;
|
||||
|
@ -465,7 +465,7 @@ vfs_path_from_str_uri_parser (char *path)
|
|||
}
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
vpath->path = g_list_prepend (vpath->path, element);
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
|
||||
if ((real_vfs_prefix_start > path && *(real_vfs_prefix_start) == PATH_SEP) ||
|
||||
(real_vfs_prefix_start == path && *(real_vfs_prefix_start) != PATH_SEP))
|
||||
|
@ -482,7 +482,7 @@ vfs_path_from_str_uri_parser (char *path)
|
|||
element->encoding = vfs_get_encoding (path);
|
||||
element->dir.converter =
|
||||
(element->encoding != NULL) ? str_crt_conv_from (element->encoding) : INVALID_CONV;
|
||||
vpath->path = g_list_prepend (vpath->path, element);
|
||||
g_array_prepend_val (vpath->path, element);
|
||||
}
|
||||
|
||||
return vpath;
|
||||
|
@ -500,7 +500,7 @@ vfs_path_from_str_uri_parser (char *path)
|
|||
|
||||
static void
|
||||
vfs_path_tokens_add_class_info (vfs_path_element_t * element, GString * ret_tokens,
|
||||
GString * element_tokens)
|
||||
GString * element_tokens)
|
||||
{
|
||||
if (((element->class->flags & VFSF_LOCAL) == 0 || ret_tokens->len > 0)
|
||||
&& element_tokens->len > 0)
|
||||
|
@ -694,7 +694,10 @@ vfs_path_t *
|
|||
vfs_path_new (void)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = g_new0 (vfs_path_t, 1);
|
||||
vpath->path = g_array_new (FALSE, TRUE, sizeof (vfs_path_element_t *));
|
||||
|
||||
return vpath;
|
||||
}
|
||||
|
||||
|
@ -710,7 +713,7 @@ vfs_path_new (void)
|
|||
int
|
||||
vfs_path_elements_count (const vfs_path_t * vpath)
|
||||
{
|
||||
return (vpath != NULL && vpath->path != NULL) ? g_list_length (vpath->path) : 0;
|
||||
return (vpath != NULL && vpath->path != NULL) ? vpath->path->len : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -732,7 +735,7 @@ vfs_path_get_by_index (const vfs_path_t * vpath, int element_index)
|
|||
if (element_index < 0)
|
||||
vfs_die ("vfs_path_get_by_index: incorrect index!");
|
||||
|
||||
return g_list_nth_data (vpath->path, element_index);
|
||||
return g_array_index (vpath->path, vfs_path_element_t *, element_index);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -805,17 +808,20 @@ vfs_path_clone (const vfs_path_t * vpath)
|
|||
{
|
||||
vfs_path_t *new_vpath;
|
||||
int vpath_element_index;
|
||||
|
||||
if (vpath == NULL)
|
||||
return NULL;
|
||||
|
||||
new_vpath = vfs_path_new ();
|
||||
|
||||
for (vpath_element_index = 0; vpath_element_index < vfs_path_elements_count (vpath);
|
||||
vpath_element_index++)
|
||||
{
|
||||
new_vpath->path =
|
||||
g_list_append (new_vpath->path,
|
||||
vfs_path_element_clone (vfs_path_get_by_index
|
||||
(vpath, vpath_element_index)));
|
||||
vfs_path_element_t *path_element;
|
||||
|
||||
path_element =
|
||||
vfs_path_element_clone (vfs_path_get_by_index (vpath, vpath_element_index));
|
||||
g_array_append_val (new_vpath->path, path_element);
|
||||
}
|
||||
|
||||
return new_vpath;
|
||||
|
@ -830,13 +836,19 @@ vfs_path_clone (const vfs_path_t * vpath)
|
|||
*/
|
||||
|
||||
void
|
||||
vfs_path_free (vfs_path_t * path)
|
||||
vfs_path_free (vfs_path_t * vpath)
|
||||
{
|
||||
if (path == NULL)
|
||||
int vpath_element_index;
|
||||
|
||||
if (vpath == NULL)
|
||||
return;
|
||||
g_list_foreach (path->path, (GFunc) vfs_path_element_free, NULL);
|
||||
g_list_free (path->path);
|
||||
g_free (path);
|
||||
|
||||
for (vpath_element_index = 0; vpath_element_index < vfs_path_elements_count (vpath);
|
||||
vpath_element_index++)
|
||||
vfs_path_element_free (vfs_path_get_by_index (vpath, vpath_element_index));
|
||||
|
||||
g_array_free (vpath->path, TRUE);
|
||||
g_free (vpath);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -859,8 +871,8 @@ vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index)
|
|||
if (element_index < 0)
|
||||
element_index = vfs_path_elements_count (vpath) + element_index;
|
||||
|
||||
element = g_list_nth_data (vpath->path, element_index);
|
||||
vpath->path = g_list_remove (vpath->path, element);
|
||||
element = vfs_path_get_by_index (vpath, element_index);
|
||||
vpath->path = g_array_remove_index (vpath->path, element_index);
|
||||
vfs_path_element_free (element);
|
||||
}
|
||||
|
||||
|
@ -1017,7 +1029,7 @@ vfs_path_deserialize (const char *data, GError ** error)
|
|||
element->host = mc_config_get_string_raw (cpath, groupname, "host", NULL);
|
||||
element->port = mc_config_get_int (cpath, groupname, "port", 0);
|
||||
|
||||
vpath->path = g_list_append (vpath->path, element);
|
||||
vpath->path = g_array_append_val (vpath->path, element);
|
||||
|
||||
g_free (groupname);
|
||||
element_index++;
|
||||
|
@ -1122,10 +1134,13 @@ vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...)
|
|||
int vindex;
|
||||
|
||||
for (vindex = 0; vindex < vfs_path_elements_count (current_vpath); vindex++)
|
||||
ret_vpath->path =
|
||||
g_list_append (ret_vpath->path,
|
||||
vfs_path_element_clone (vfs_path_get_by_index
|
||||
(current_vpath, vindex)));
|
||||
{
|
||||
vfs_path_element_t *path_element;
|
||||
|
||||
path_element =
|
||||
vfs_path_element_clone (vfs_path_get_by_index (current_vpath, vindex));
|
||||
g_array_append_val (ret_vpath->path, path_element);
|
||||
}
|
||||
current_vpath = va_arg (args, const vfs_path_t *);
|
||||
}
|
||||
while (current_vpath != NULL);
|
||||
|
|
|
@ -21,7 +21,7 @@ struct vfs_url_struct;
|
|||
|
||||
typedef struct
|
||||
{
|
||||
GList *path;
|
||||
GArray *path;
|
||||
} vfs_path_t;
|
||||
|
||||
typedef struct
|
||||
|
|
Loading…
Reference in New Issue