aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbUtils.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-08 11:47:57 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-09 00:40:26 -0700
commit09dccb79f611110a5a653030c7c21958eda95a03 (patch)
treec1132f3228146c9543806c36451056a61a1f7f8e /src/dbUtils.c
parent65c88720fbc08bb9ca2cb37ffa75fd842ff3f1d1 (diff)
downloadmpd-09dccb79f611110a5a653030c7c21958eda95a03.tar.gz
mpd-09dccb79f611110a5a653030c7c21958eda95a03.tar.xz
mpd-09dccb79f611110a5a653030c7c21958eda95a03.zip
use strset.h instead of tagTracker.h
With a large music database, the linear string collection in tagTracker.c becomes very slow. We implemented that in a quick'n'dirty fashion when we removed tree.c, and now we rewrite it using the fast hashed string set.
Diffstat (limited to 'src/dbUtils.c')
-rw-r--r--src/dbUtils.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c
index d39c9908c..00fa1d441 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -24,7 +24,7 @@
#include "playlist.h"
#include "song.h"
#include "tag.h"
-#include "tagTracker.h"
+#include "strset.h"
#include "log.h"
#include "storedPlaylist.h"
@@ -254,7 +254,8 @@ static void freeListCommandItem(ListCommandItem * item)
free(item);
}
-static void visitTag(int fd, Song * song, enum tag_type tagType)
+static void visitTag(int fd, struct strset *set,
+ Song * song, enum tag_type tagType)
{
int i;
struct mpd_tag *tag = song->tag;
@@ -269,18 +270,25 @@ static void visitTag(int fd, Song * song, enum tag_type tagType)
for (i = 0; i < tag->numOfItems; i++) {
if (tag->items[i]->type == tagType) {
- visitInTagTracker(tagType, tag->items[i]->value);
+ strset_add(set, tag->items[i]->value);
}
}
}
-static int listUniqueTagsInDirectory(int fd, Song * song, void *data)
+struct list_tags_data {
+ int fd;
+ ListCommandItem *item;
+ struct strset *set;
+};
+
+static int listUniqueTagsInDirectory(int fd, Song * song, void *_data)
{
- ListCommandItem *item = data;
+ struct list_tags_data *data = _data;
+ ListCommandItem *item = data->item;
if (tagItemsFoundAndMatches(song, item->numConditionals,
item->conditionals)) {
- visitTag(fd, song, item->tagType);
+ visitTag(fd, data->set, song, item->tagType);
}
return 0;
@@ -290,18 +298,28 @@ int listAllUniqueTags(int fd, int type, int numConditionals,
LocateTagItem * conditionals)
{
int ret;
+ struct list_tags_data data;
ListCommandItem *item = newListCommandItem(type, numConditionals,
conditionals);
+ data.fd = fd;
+ data.item = item;
+
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
- resetVisitedFlagsInTagTracker(type);
+ data.set = strset_new();
}
- ret = traverseAllIn(fd, NULL, listUniqueTagsInDirectory, NULL,
- (void *)item);
+ ret = traverseAllIn(fd, NULL, listUniqueTagsInDirectory, NULL, &data);
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
- printVisitedInTagTracker(fd, type);
+ const char *value;
+
+ strset_rewind(data.set);
+
+ while ((value = strset_next(data.set)) != NULL)
+ fdprintf(fd, "%s: %s\n", mpdTagItemKeys[type], value);
+
+ strset_free(data.set);
}
freeListCommandItem(item);