diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-13 09:55:00 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-13 09:55:00 +0200 |
commit | 8d907fb9fafaeddeb237e494ff461d2df6c03af4 (patch) | |
tree | aa28b4fa8cdb1de45662b9cc4b12710b7797f7cd /src/directory.c | |
parent | 8867bd554c6acd508d41f80457bac242a36e61fc (diff) | |
download | mpd-8d907fb9fafaeddeb237e494ff461d2df6c03af4.tar.gz mpd-8d907fb9fafaeddeb237e494ff461d2df6c03af4.tar.xz mpd-8d907fb9fafaeddeb237e494ff461d2df6c03af4.zip |
directory: use mpd_sizeof_str_flex_array for path, too
This way we avoid unnecessary heap allocations.
Diffstat (limited to '')
-rw-r--r-- | src/directory.c | 13 |
1 files changed, 7 insertions, 6 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 <string.h> 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); */ |