directory: added directory_is_root()

directory_is_root() is cheaper than
isRootDirectory(directory_get_path()).
This commit is contained in:
Max Kellermann 2009-01-04 19:08:52 +01:00
parent 923d2c966f
commit ea8ae68e6f
6 changed files with 18 additions and 8 deletions

View File

@ -64,9 +64,10 @@ static int
printDirectoryInDirectory(struct directory *directory, void *data)
{
struct client *client = data;
if (!isRootDirectory(directory->path)) {
if (!directory_is_root(directory))
client_printf(client, "directory: %s\n", directory_get_path(directory));
}
return 0;
}
@ -374,7 +375,7 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data)
{
int *sum = data;
if (isRootDirectory(dir->path))
if (directory_is_root(dir))
return 0;
*sum += (strlen(directory_get_path(dir)) + 1

View File

@ -70,6 +70,15 @@ directory_get_path(const struct directory *directory)
return directory->path;
}
/**
* Is this the root directory of the music database?
*/
static inline bool
directory_is_root(const struct directory *directory)
{
return directory->parent == NULL;
}
/**
* Returns the base name of the directory.
*/

View File

@ -36,7 +36,7 @@ directory_save(FILE *fp, struct directory *directory)
size_t i;
int retv;
if (!isRootDirectory(directory->path)) {
if (!directory_is_root(directory)) {
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
directory_get_path(directory));
if (retv < 0)
@ -57,7 +57,7 @@ directory_save(FILE *fp, struct directory *directory)
songvec_save(fp, &directory->songs);
if (!isRootDirectory(directory->path) &&
if (!directory_is_root(directory) &&
fprintf(fp, DIRECTORY_END "%s\n",
directory_get_path(directory)) < 0)
return -1;

View File

@ -181,7 +181,7 @@ song_get_url(const struct song *song, char *path_max_tmp)
assert(song != NULL);
assert(*song->url);
if (!song->parent || isRootDirectory(song->parent->path))
if (!song_in_database(song) || directory_is_root(song->parent))
strcpy(path_max_tmp, song->url);
else
pfx_dir(path_max_tmp, song->url, strlen(song->url),

View File

@ -26,7 +26,7 @@
void
song_print_url(struct client *client, struct song *song)
{
if (song->parent && !isRootDirectory(song->parent->path)) {
if (song_in_database(song) && !directory_is_root(song->parent)) {
client_printf(client, "%s%s/%s\n", SONG_FILE,
directory_get_path(song->parent), song->url);
} else {

View File

@ -290,7 +290,7 @@ make_subdir(struct directory *parent, const char *name)
if (directory == NULL) {
char path[MPD_PATH_MAX];
if (isRootDirectory(directory_get_path(parent)))
if (directory_is_root(parent))
strcpy(path, name);
else
pfx_dir(path, name, strlen(name),