diff options
author | Max Kellermann <max@duempel.org> | 2008-09-08 11:47:57 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-08 11:47:57 +0200 |
commit | f0e64ceb48c485baf32528bba44875885d384354 (patch) | |
tree | c9869f5a5dd25a7eb88791ca6aa95f7c0e77168c /src/stats.c | |
parent | 2b8040b42524dad68ea85c45a4be25909a03eb5c (diff) | |
download | mpd-f0e64ceb48c485baf32528bba44875885d384354.tar.gz mpd-f0e64ceb48c485baf32528bba44875885d384354.tar.xz mpd-f0e64ceb48c485baf32528bba44875885d384354.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 '')
-rw-r--r-- | src/stats.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/stats.c b/src/stats.c index 280450f14..ee0854e16 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1,5 +1,6 @@ /* the Music Player Daemon (MPD) * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com) + * Copyright (C) 2008 Max Kellermann <max@duempel.org> * This project's homepage is: http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -22,7 +23,7 @@ #include "tag.h" #include "client.h" #include "player_control.h" -#include "tagTracker.h" +#include "strset.h" #include "os_compat.h" Stats stats; @@ -33,11 +34,48 @@ void initStats(void) stats.numberOfSongs = 0; } +struct visit_data { + enum tag_type type; + struct strset *set; +}; + +static int visit_tag_items(Song *song, void *_data) +{ + const struct visit_data *data = _data; + unsigned i; + + if (song->tag == NULL) + return 0; + + for (i = 0; i < (unsigned)song->tag->numOfItems; ++i) { + const struct tag_item *item = song->tag->items[i]; + if (item->type == data->type) + strset_add(data->set, item->value); + } + + return 0; +} + +static unsigned int getNumberOfTagItems(int type) +{ + struct visit_data data = { + .type = type, + .set = strset_new(), + }; + unsigned int ret; + + traverseAllIn(NULL, visit_tag_items, NULL, &data); + + ret = strset_size(data.set); + strset_free(data.set); + return ret; +} + int printStats(struct client *client) { client_printf(client, - "artists: %i\n" - "albums: %i\n" + "artists: %u\n" + "albums: %u\n" "songs: %i\n" "uptime: %li\n" "playtime: %li\n" |