diff options
author | Max Kellermann <max@duempel.org> | 2008-08-29 09:38:29 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-09-02 00:15:38 -0700 |
commit | 6aa1a7a2565bd1789fd34c7c71d5dbb34eaa1fee (patch) | |
tree | 8b6022cf1239a0a6962377827b1cb519b20f43ab /src | |
parent | 323835240107ba08c080bbd8ed7aebe742fc4475 (diff) | |
download | mpd-6aa1a7a2565bd1789fd34c7c71d5dbb34eaa1fee.tar.gz mpd-6aa1a7a2565bd1789fd34c7c71d5dbb34eaa1fee.tar.xz mpd-6aa1a7a2565bd1789fd34c7c71d5dbb34eaa1fee.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/dbUtils.c | 4 | ||||
-rw-r--r-- | src/locate.c | 8 | ||||
-rw-r--r-- | src/tag.c | 23 | ||||
-rw-r--r-- | 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; } @@ -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); } @@ -46,7 +46,7 @@ struct tag_item { struct mpd_tag { int time; - struct tag_item *items; + struct tag_item **items; mpd_uint8 numOfItems; }; |