(vfs_path_tokens_count): refactoring: get rid of extra memory allocation.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
87a5f11452
Коммит
26fbddf6f4
@ -1338,19 +1338,22 @@ vfs_path_tokens_count (const vfs_path_t * vpath)
|
||||
for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
|
||||
{
|
||||
const vfs_path_element_t *element;
|
||||
char **path_tokens, **iterator;
|
||||
const char *token, *prev_token;
|
||||
|
||||
element = vfs_path_get_by_index (vpath, element_index);
|
||||
path_tokens = iterator = g_strsplit (element->path, PATH_SEP_STR, -1);
|
||||
|
||||
while (*iterator != NULL)
|
||||
for (prev_token = element->path; (token = strchr (prev_token, PATH_SEP)) != NULL;
|
||||
prev_token = token + 1)
|
||||
{
|
||||
if (**iterator != '\0')
|
||||
/* skip empty substring */
|
||||
if (token != prev_token)
|
||||
count_tokens++;
|
||||
iterator++;
|
||||
}
|
||||
g_strfreev (path_tokens);
|
||||
|
||||
if (*prev_token != '\0')
|
||||
count_tokens++;
|
||||
}
|
||||
|
||||
return count_tokens;
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user