From 8d907fb9fafaeddeb237e494ff461d2df6c03af4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 13 Oct 2008 09:55:00 +0200 Subject: directory: use mpd_sizeof_str_flex_array for path, too This way we avoid unnecessary heap allocations. --- src/directory.c | 13 +++++++------ src/directory.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/directory.c b/src/directory.c index e63310026..002cb65e3 100644 --- a/src/directory.c +++ b/src/directory.c @@ -23,16 +23,18 @@ #include struct directory * -directory_new(const char *dirname, struct directory *parent) +directory_new(const char *path, struct directory *parent) { struct directory *directory; + size_t pathlen = strlen(path); - assert(dirname != NULL); - assert((*dirname == 0) == (parent == NULL)); + assert(path != NULL); + assert((*path == 0) == (parent == NULL)); - directory = xcalloc(1, sizeof(*directory)); - directory->path = xstrdup(dirname); + directory = xcalloc(1, sizeof(*directory) - + sizeof(directory->path) + pathlen + 1); directory->parent = parent; + memcpy(directory->path, path, pathlen + 1); return directory; } @@ -42,7 +44,6 @@ directory_free(struct directory *directory) { dirvec_destroy(&directory->children); songvec_destroy(&directory->songs); - free(directory->path); free(directory); /* this resets last dir returned */ /*directory_get_path(NULL); */ diff --git a/src/directory.h b/src/directory.h index 9dd064ef7..4e50cf1e8 100644 --- a/src/directory.h +++ b/src/directory.h @@ -35,13 +35,13 @@ #define DIRECTORY_FS_CHARSET "fs_charset: " struct directory { - char *path; struct dirvec children; struct songvec songs; struct directory *parent; ino_t inode; dev_t device; unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */ + char path[sizeof(long)]; }; static inline bool -- cgit v1.2.3