diff options
Diffstat (limited to 'src/Directory.cxx')
-rw-r--r-- | src/Directory.cxx | 69 |
1 files changed, 13 insertions, 56 deletions
diff --git a/src/Directory.cxx b/src/Directory.cxx index b2942588e..28c2c47e1 100644 --- a/src/Directory.cxx +++ b/src/Directory.cxx @@ -25,6 +25,7 @@ #include "SongSort.hxx" #include "Song.hxx" #include "fs/Traits.hxx" +#include "util/Alloc.hxx" #include "util/Error.hxx" extern "C" { @@ -37,35 +38,11 @@ extern "C" { #include <string.h> #include <stdlib.h> -inline Directory * -Directory::Allocate(const char *path) -{ - assert(path != nullptr); - - const size_t path_size = strlen(path) + 1; - Directory *directory = - (Directory *)g_malloc0(sizeof(*directory) - - sizeof(directory->path) - + path_size); - new(directory) Directory(path); - - return directory; -} - -Directory::Directory() -{ - INIT_LIST_HEAD(&children); - INIT_LIST_HEAD(&songs); - - path[0] = 0; -} - -Directory::Directory(const char *_path) +Directory::Directory(const char *_path_utf8, Directory *_parent) + :parent(_parent), path(_path_utf8) { INIT_LIST_HEAD(&children); INIT_LIST_HEAD(&songs); - - strcpy(path, _path); } Directory::~Directory() @@ -76,27 +53,7 @@ Directory::~Directory() Directory *child, *n; directory_for_each_child_safe(child, n, *this) - child->Free(); -} - -Directory * -Directory::NewGeneric(const char *path, Directory *parent) -{ - assert(path != nullptr); - assert((*path == 0) == (parent == nullptr)); - - Directory *directory = Allocate(path); - - directory->parent = parent; - - return directory; -} - -void -Directory::Free() -{ - this->Directory::~Directory(); - g_free(this); + delete child; } void @@ -106,7 +63,7 @@ Directory::Delete() assert(parent != nullptr); list_del(&siblings); - Free(); + delete this; } const char * @@ -114,7 +71,7 @@ Directory::GetName() const { assert(!IsRoot()); - return PathTraits::GetBaseUTF8(path); + return PathTraitsUTF8::GetBase(path.c_str()); } Directory * @@ -135,7 +92,7 @@ Directory::CreateChild(const char *name_utf8) path_utf8 = allocated; } - Directory *child = NewGeneric(path_utf8, this); + Directory *child = new Directory(path_utf8, this); g_free(allocated); list_add_tail(&child->siblings, &children); @@ -178,7 +135,7 @@ Directory::LookupDirectory(const char *uri) if (isRootDirectory(uri)) return this; - char *duplicated = g_strdup(uri), *name = duplicated; + char *duplicated = xstrdup(uri), *name = duplicated; Directory *d = this; while (1) { @@ -198,7 +155,7 @@ Directory::LookupDirectory(const char *uri) name = slash + 1; } - g_free(duplicated); + free(duplicated); return d; } @@ -248,7 +205,7 @@ Directory::LookupSong(const char *uri) assert(holding_db_lock()); assert(uri != nullptr); - duplicated = g_strdup(uri); + duplicated = xstrdup(uri); base = strrchr(duplicated, '/'); Directory *d = this; @@ -256,7 +213,7 @@ Directory::LookupSong(const char *uri) *base++ = 0; d = d->LookupDirectory(duplicated); if (d == nullptr) { - g_free(duplicated); + free(duplicated); return nullptr; } } else @@ -265,7 +222,7 @@ Directory::LookupSong(const char *uri) Song *song = d->FindSong(base); assert(song == nullptr || song->parent == d); - g_free(duplicated); + free(duplicated); return song; } @@ -276,7 +233,7 @@ directory_cmp(gcc_unused void *priv, { const Directory *a = (const Directory *)_a; const Directory *b = (const Directory *)_b; - return g_utf8_collate(a->path, b->path); + return g_utf8_collate(a->path.c_str(), b->path.c_str()); } void |