From 6aa1a7a2565bd1789fd34c7c71d5dbb34eaa1fee Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 29 Aug 2008 09:38:29 +0200 Subject: tag: converted MpdTag.items to a pointer list This prepares the following patches, which aim to reduce MPD's memory usage: we plan to share tag_item instances, instead of just their values. --- src/dbUtils.c | 4 ++-- src/locate.c | 8 ++++---- src/tag.c | 23 +++++++++++++---------- src/tag.h | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/dbUtils.c b/src/dbUtils.c index 3379b9bb2..d39c9908c 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -268,8 +268,8 @@ static void visitTag(int fd, Song * song, enum tag_type tagType) return; for (i = 0; i < tag->numOfItems; i++) { - if (tag->items[i].type == tagType) { - visitInTagTracker(tagType, tag->items[i].value); + if (tag->items[i]->type == tagType) { + visitInTagTracker(tagType, tag->items[i]->value); } } } diff --git a/src/locate.c b/src/locate.c index f68afdedb..76e229f4c 100644 --- a/src/locate.c +++ b/src/locate.c @@ -142,11 +142,11 @@ static int strstrSearchTag(Song * song, enum tag_type type, char *str) for (i = 0; i < song->tag->numOfItems && !ret; i++) { if (type != LOCATE_TAG_ANY_TYPE && - song->tag->items[i].type != type) { + song->tag->items[i]->type != type) { continue; } - duplicate = strDupToUpper(song->tag->items[i].value); + duplicate = strDupToUpper(song->tag->items[i]->value); if (strstr(duplicate, str)) ret = 1; free(duplicate); @@ -186,11 +186,11 @@ static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str) for (i = 0; i < song->tag->numOfItems; i++) { if (type != LOCATE_TAG_ANY_TYPE && - song->tag->items[i].type != type) { + song->tag->items[i]->type != type) { continue; } - if (0 == strcmp(str, song->tag->items[i].value)) + if (0 == strcmp(str, song->tag->items[i]->value)) return 1; } diff --git a/src/tag.c b/src/tag.c index d06c6c31e..311b49d50 100644 --- a/src/tag.c +++ b/src/tag.c @@ -108,8 +108,8 @@ void tag_print(int fd, struct mpd_tag *tag) fdprintf(fd, SONG_TIME "%i\n", tag->time); for (i = 0; i < tag->numOfItems; i++) { - fdprintf(fd, "%s: %s\n", mpdTagItemKeys[tag->items[i].type], - tag->items[i].value); + fdprintf(fd, "%s: %s\n", mpdTagItemKeys[tag->items[i]->type], + tag->items[i]->value); } } @@ -248,7 +248,8 @@ static void deleteItem(struct mpd_tag *tag, int idx) assert(idx < tag->numOfItems); tag->numOfItems--; - removeTagItemString(tag->items[idx].type, tag->items[idx].value); + removeTagItemString(tag->items[idx]->type, tag->items[idx]->value); + free(tag->items[idx]); /* free(tag->items[idx].value); */ if (tag->numOfItems - idx > 0) { @@ -270,7 +271,7 @@ void tag_clear_items_by_type(struct mpd_tag *tag, enum tag_type type) int i; for (i = 0; i < tag->numOfItems; i++) { - if (tag->items[i].type == type) { + if (tag->items[i]->type == type) { deleteItem(tag, i); /* decrement since when just deleted this node */ i--; @@ -283,8 +284,9 @@ static void clearMpdTag(struct mpd_tag *tag) int i; for (i = 0; i < tag->numOfItems; i++) { - removeTagItemString(tag->items[i].type, tag->items[i].value); + removeTagItemString(tag->items[i]->type, tag->items[i]->value); /* free(tag->items[i].value); */ + free(tag->items[i]); } if (tag->items) @@ -314,7 +316,7 @@ struct mpd_tag *tag_dup(struct mpd_tag *tag) ret->time = tag->time; for (i = 0; i < tag->numOfItems; i++) { - tag_add_item(ret, tag->items[i].type, tag->items[i].value); + tag_add_item(ret, tag->items[i]->type, tag->items[i]->value); } return ret; @@ -336,9 +338,9 @@ int tag_equal(struct mpd_tag *tag1, struct mpd_tag *tag2) return 0; for (i = 0; i < tag1->numOfItems; i++) { - if (tag1->items[i].type != tag2->items[i].type) + if (tag1->items[i]->type != tag2->items[i]->type) return 0; - if (strcmp(tag1->items[i].value, tag2->items[i].value)) { + if (strcmp(tag1->items[i]->value, tag2->items[i]->value)) { return 0; } } @@ -372,8 +374,9 @@ static void appendToTagItems(struct mpd_tag *tag, enum tag_type type, tag->items = xrealloc(tag->items, tag->numOfItems * sizeof(*tag->items)); - tag->items[i].type = type; - tag->items[i].value = getTagItemString(type, duplicated); + tag->items[i] = xmalloc(sizeof(*tag->items[i])); + tag->items[i]->type = type; + tag->items[i]->value = getTagItemString(type, duplicated); free(duplicated); } diff --git a/src/tag.h b/src/tag.h index f9a02d41a..4ee93ee1f 100644 --- a/src/tag.h +++ b/src/tag.h @@ -46,7 +46,7 @@ struct tag_item { struct mpd_tag { int time; - struct tag_item *items; + struct tag_item **items; mpd_uint8 numOfItems; }; -- cgit v1.2.3