From c6ee14dca5d7336dad20a6057aa2a8006d4447b8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Oct 2008 20:24:26 -0700 Subject: directory: use mpd_sizeof_str_flex_array for path, too This way we avoid unnecessary heap allocations. --- src/directory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/directory.c') diff --git a/src/directory.c b/src/directory.c index b90b477fd..699b6fbc1 100644 --- a/src/directory.c +++ b/src/directory.c @@ -23,15 +23,16 @@ #include "myfprintf.h" #include "dirvec.h" -struct directory * directory_new(const char *dirname, struct directory * parent) +struct directory * directory_new(const char *path, struct directory * parent) { struct directory *dir; + size_t pathlen = strlen(path); - assert(dirname != NULL); - assert((*dirname == 0) == (parent == NULL)); + assert(path != NULL); + assert((*path == 0) == (parent == NULL)); - dir = xcalloc(1, sizeof(struct directory)); - dir->path = xstrdup(dirname); + dir = xcalloc(1, sizeof(*dir) - sizeof(dir->path) + pathlen + 1); + memcpy(dir->path, path, pathlen + 1); dir->parent = parent; return dir; @@ -41,7 +42,6 @@ void directory_free(struct directory *dir) { dirvec_destroy(&dir->children); songvec_destroy(&dir->songs); - free(dir->path); free(dir); /* this resets last dir returned */ /*directory_get_path(NULL); */ -- cgit v1.2.3