aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-29 09:38:29 +0200
committerMax Kellermann <max@duempel.org>2008-08-29 09:38:29 +0200
commitad0e09b2db5ebf428acc98f90c3ef0dd171bebbb (patch)
tree8d3421da76a85ec1918a4fc479d2d60b5a3904d1 /src
parent6f72fe3ecffd8ee8218fc5a19ec45b0447323c12 (diff)
downloadmpd-ad0e09b2db5ebf428acc98f90c3ef0dd171bebbb.tar.gz
mpd-ad0e09b2db5ebf428acc98f90c3ef0dd171bebbb.tar.xz
mpd-ad0e09b2db5ebf428acc98f90c3ef0dd171bebbb.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 '')
-rw-r--r--src/dbUtils.c4
-rw-r--r--src/locate.c8
-rw-r--r--src/tag.c23
-rw-r--r--src/tag.h2
4 files changed, 20 insertions, 17 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 1d66e316d..1c758476d 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 3b3da2316..a856dc979 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -108,8 +108,8 @@ void tag_print(int fd, struct 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 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 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 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 tag *tag_dup(struct 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 tag *tag1, struct 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 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 51cd64cdc..1618c0f59 100644
--- a/src/tag.h
+++ b/src/tag.h
@@ -46,7 +46,7 @@ struct tag_item {
struct tag {
int time;
- struct tag_item *items;
+ struct tag_item **items;
mpd_uint8 numOfItems;
};