aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-09 13:14:14 +0100
committerMax Kellermann <max@duempel.org>2014-01-09 13:14:14 +0100
commit91efe1cb5ab4499512bf74b45221e800cc048726 (patch)
tree4dc541ed7085a0bbc2bd7c5b3bc43c458578f29f /src
parent735241f04922f9d666bf76dd003d2a6b03096f31 (diff)
downloadmpd-91efe1cb5ab4499512bf74b45221e800cc048726.tar.gz
mpd-91efe1cb5ab4499512bf74b45221e800cc048726.tar.xz
mpd-91efe1cb5ab4499512bf74b45221e800cc048726.zip
Directory: convert to fixed-size struct
Using a variable-size struct with embedded string is not worth the trouble here. There are not so many Directory objects.
Diffstat (limited to '')
-rw-r--r--src/Directory.cxx43
-rw-r--r--src/Directory.hxx28
2 files changed, 15 insertions, 56 deletions
diff --git a/src/Directory.cxx b/src/Directory.cxx
index 9180427f9..87585818e 100644
--- a/src/Directory.cxx
+++ b/src/Directory.cxx
@@ -25,7 +25,7 @@
#include "SongSort.hxx"
#include "Song.hxx"
#include "fs/Traits.hxx"
-#include "util/VarSize.hxx"
+#include "util/Alloc.hxx"
#include "util/Error.hxx"
extern "C" {
@@ -38,23 +38,11 @@ extern "C" {
#include <string.h>
#include <stdlib.h>
-inline Directory *
-Directory::Allocate(const char *path)
-{
- assert(path != nullptr);
-
- return NewVarSize<Directory>(sizeof(Directory::path),
- strlen(path) + 1,
- path);
-}
-
-Directory::Directory(const char *_path)
- :mtime(0), have_stat(false)
+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()
@@ -68,25 +56,6 @@ Directory::~Directory()
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()
-{
- DeleteVarSize(this);
-}
-
void
Directory::Delete()
{
@@ -102,7 +71,7 @@ Directory::GetName() const
{
assert(!IsRoot());
- return PathTraitsUTF8::GetBase(path);
+ return PathTraitsUTF8::GetBase(path.c_str());
}
Directory *
@@ -123,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);
@@ -264,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
diff --git a/src/Directory.hxx b/src/Directory.hxx
index 24ba685e6..a8e3e32cb 100644
--- a/src/Directory.hxx
+++ b/src/Directory.hxx
@@ -26,6 +26,8 @@
#include "DatabaseVisitor.hxx"
#include "PlaylistVector.hxx"
+#include <string>
+
#include <sys/types.h>
#define DEVICE_INARCHIVE (dev_t)(-1)
@@ -49,10 +51,6 @@ class SongFilter;
class Error;
struct Directory {
- template<class T, typename... Args> friend T *
- NewVarSize(size_t declared_tail_size, size_t real_tail_size,
- Args&&... args);
-
/**
* Pointers to the siblings of this directory within the
* parent directory. It is unused (undefined) in the root
@@ -86,36 +84,28 @@ struct Directory {
ino_t inode;
dev_t device;
bool have_stat; /* not needed if ino_t == dev_t == 0 is impossible */
- char path[sizeof(long)];
-protected:
- Directory(const char *path);
-
- gcc_malloc gcc_nonnull_all
- static Directory *Allocate(const char *path);
+ std::string path;
public:
+ Directory(const char *_path_utf8, Directory *_parent);
~Directory();
/**
- * Generic constructor for #Directory object.
- */
- gcc_malloc
- static Directory *NewGeneric(const char *path_utf8, Directory *parent);
-
- /**
* Create a new root #Directory object.
*/
gcc_malloc
static Directory *NewRoot() {
- return NewGeneric("", nullptr);
+ return new Directory("", nullptr);
}
/**
* Free this #Directory object (and the whole object tree within it),
* assuming it was already removed from the parent.
*/
- void Free();
+ void Free() {
+ delete this;
+ }
/**
* Remove this #Directory object from its parent and free it. This
@@ -178,7 +168,7 @@ public:
gcc_pure
const char *GetPath() const {
- return path;
+ return path.c_str();
}
/**