tag: converted tag_item.value to a char array
The value is stored in the same memory allocation as the tag_item struct; this saves memory because we do not store the value pointer anymore. Also remove the getTagItemString()/removeTagItemString() dummies.
This commit is contained in:
parent
b731bbe93a
commit
e5a7879892
@ -248,7 +248,6 @@ static void deleteItem(struct tag *tag, int idx)
|
|||||||
assert(idx < tag->numOfItems);
|
assert(idx < tag->numOfItems);
|
||||||
tag->numOfItems--;
|
tag->numOfItems--;
|
||||||
|
|
||||||
removeTagItemString(tag->items[idx]->type, tag->items[idx]->value);
|
|
||||||
free(tag->items[idx]);
|
free(tag->items[idx]);
|
||||||
/* free(tag->items[idx].value); */
|
/* free(tag->items[idx].value); */
|
||||||
|
|
||||||
@ -284,7 +283,6 @@ static void clearMpdTag(struct tag *tag)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < tag->numOfItems; i++) {
|
for (i = 0; i < tag->numOfItems; i++) {
|
||||||
removeTagItemString(tag->items[i]->type, tag->items[i]->value);
|
|
||||||
/* free(tag->items[i].value); */
|
/* free(tag->items[i].value); */
|
||||||
free(tag->items[i]);
|
free(tag->items[i]);
|
||||||
}
|
}
|
||||||
@ -374,9 +372,10 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
|
|||||||
tag->items = xrealloc(tag->items,
|
tag->items = xrealloc(tag->items,
|
||||||
tag->numOfItems * sizeof(*tag->items));
|
tag->numOfItems * sizeof(*tag->items));
|
||||||
|
|
||||||
tag->items[i] = xmalloc(sizeof(*tag->items[i]));
|
len = strlen(duplicated);
|
||||||
|
tag->items[i] = xmalloc(sizeof(*tag->items[i]) + len);
|
||||||
tag->items[i]->type = type;
|
tag->items[i]->type = type;
|
||||||
tag->items[i]->value = getTagItemString(type, duplicated);
|
memcpy(tag->items[i]->value, duplicated, len + 1);
|
||||||
|
|
||||||
free(duplicated);
|
free(duplicated);
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ extern const char *mpdTagItemKeys[];
|
|||||||
|
|
||||||
struct tag_item {
|
struct tag_item {
|
||||||
enum tag_type type;
|
enum tag_type type;
|
||||||
char *value;
|
char value[1];
|
||||||
};
|
} mpd_unused;
|
||||||
|
|
||||||
struct tag {
|
struct tag {
|
||||||
int time;
|
int time;
|
||||||
|
@ -37,16 +37,6 @@ struct visited {
|
|||||||
static struct visited *visited_heads[TAG_NUM_OF_ITEM_TYPES];
|
static struct visited *visited_heads[TAG_NUM_OF_ITEM_TYPES];
|
||||||
static unsigned num_visited[TAG_NUM_OF_ITEM_TYPES];
|
static unsigned num_visited[TAG_NUM_OF_ITEM_TYPES];
|
||||||
|
|
||||||
char *getTagItemString(int type mpd_unused, char *string)
|
|
||||||
{
|
|
||||||
return xstrdup(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeTagItemString(int type mpd_unused, char *string)
|
|
||||||
{
|
|
||||||
free(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int visit_tag_items(int fd mpd_unused, Song *song, void *data)
|
static int visit_tag_items(int fd mpd_unused, Song *song, void *data)
|
||||||
{
|
{
|
||||||
enum tag_type type = (enum tag_type)(size_t)data;
|
enum tag_type type = (enum tag_type)(size_t)data;
|
||||||
|
@ -19,10 +19,6 @@
|
|||||||
#ifndef TAG_TRACKER_H
|
#ifndef TAG_TRACKER_H
|
||||||
#define TAG_TRACKER_H
|
#define TAG_TRACKER_H
|
||||||
|
|
||||||
char *getTagItemString(int type, char *string);
|
|
||||||
|
|
||||||
void removeTagItemString(int type, char *string);
|
|
||||||
|
|
||||||
int getNumberOfTagItems(int type);
|
int getNumberOfTagItems(int type);
|
||||||
|
|
||||||
void printMemorySavedByTagTracker(void);
|
void printMemorySavedByTagTracker(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user