From f0e64ceb48c485baf32528bba44875885d384354 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 8 Sep 2008 11:47:57 +0200 Subject: 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. --- src/stats.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'src/stats.c') 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 * 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" -- cgit v1.2.3