Optimization of extfs_get_path_from_entry() function.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2010-01-28 15:20:41 +00:00
parent ad9c1daad8
commit 5b96caa5f0

View File

@ -619,35 +619,18 @@ extfs_get_path (struct vfs_class *me, const char *inname,
static char * static char *
extfs_get_path_from_entry (struct entry *entry) extfs_get_path_from_entry (struct entry *entry)
{ {
struct list { GString *localpath;
struct list *next;
char *name;
} *head, *p;
char *localpath;
size_t len;
for (len = 0, head = 0; entry->dir; entry = entry->dir) { localpath = g_string_new ("");
p = g_new (struct list, 1);
p->next = head; while (entry->dir != NULL) {
p->name = entry->name; g_string_prepend (localpath, entry->name);
head = p; if (entry->dir->dir != NULL)
len += strlen (entry->name) + 1; g_string_prepend_c (localpath, PATH_SEP);
entry = entry->dir;
} }
if (len == 0) return g_string_free (localpath, FALSE);
return g_strdup ("");
localpath = g_malloc (len);
*localpath = '\0';
while (head) {
strcat (localpath, head->name);
if (head->next)
strcat (localpath, "/");
p = head;
head = head->next;
g_free (p);
}
return (localpath);
} }
static struct entry * static struct entry *