aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-29 09:39:08 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-02 00:20:20 -0700
commitc82544458231694c197b0c967f6e2844e8612bc6 (patch)
treecb1d059950bcdbd31bb6f93a295fc393747df2a7 /src/song.c
parentff13366268bde4493b431f50ae8fa8fcff2c9c80 (diff)
downloadmpd-c82544458231694c197b0c967f6e2844e8612bc6.tar.gz
mpd-c82544458231694c197b0c967f6e2844e8612bc6.tar.xz
mpd-c82544458231694c197b0c967f6e2844e8612bc6.zip
tag: try not to reallocate tag.items in every add() call
If many tag_items are added at once while the tag cache is being loaded, manage these items in a static fixed list, instead of reallocating the list with every newly created item. This reduces heap fragmentation. Massif results again: mk before: total 12,837,632; useful 10,626,383; extra 2,211,249 mk now: total 12,736,720; useful 10,626,383; extra 2,110,337 The "useful" value is the same since this patch only changes the way we allocate the same amount of memory, but heap fragmentation was reduced by 5%.
Diffstat (limited to '')
-rw-r--r--src/song.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/song.c b/src/song.c
index deba96ada..063b0a7b6 100644
--- a/src/song.c
+++ b/src/song.c
@@ -239,9 +239,12 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
while (myFgets(buffer, bufferSize, fp) && 0 != strcmp(SONG_END, buffer)) {
if (0 == strncmp(SONG_KEY, buffer, strlen(SONG_KEY))) {
- if (song)
+ if (song) {
insertSongIntoList(list, &nextSongNode,
song->url, song);
+ if (song->tag != NULL)
+ tag_end_add(song->tag);
+ }
song = newNullSong();
song->url = xstrdup(buffer + strlen(SONG_KEY));
@@ -256,15 +259,21 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
song->url = xstrdup(&(buffer[strlen(SONG_FILE)]));
*/
} else if (matchesAnMpdTagItemKey(buffer, &itemType)) {
- if (!song->tag)
+ if (!song->tag) {
song->tag = tag_new();
+ tag_begin_add(song->tag);
+ }
+
tag_add_item(song->tag, itemType,
&(buffer
[strlen(mpdTagItemKeys[itemType]) +
2]));
} else if (0 == strncmp(SONG_TIME, buffer, strlen(SONG_TIME))) {
- if (!song->tag)
+ if (!song->tag) {
song->tag = tag_new();
+ tag_begin_add(song->tag);
+ }
+
song->tag->time = atoi(&(buffer[strlen(SONG_TIME)]));
} else if (0 == strncmp(SONG_MTIME, buffer, strlen(SONG_MTIME))) {
song->mtime = atoi(&(buffer[strlen(SONG_MTIME)]));
@@ -273,8 +282,11 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
FATAL("songinfo: unknown line in db: %s\n", buffer);
}
- if (song)
+ if (song) {
insertSongIntoList(list, &nextSongNode, song->url, song);
+ if (song->tag != NULL)
+ tag_end_add(song->tag);
+ }
while (nextSongNode) {
nodeTemp = nextSongNode->nextNode;