aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-11-11 04:34:26 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-11-11 04:34:26 +0000
commit21b5cde43ac7c82b1848145456b98e2c5b8e6cb1 (patch)
tree12a873c1586191a39356a7822692e841fa61508a /src/song.c
parent6e0c4369c37df64764e3aaa49365d6560a3a3806 (diff)
downloadmpd-21b5cde43ac7c82b1848145456b98e2c5b8e6cb1.tar.gz
mpd-21b5cde43ac7c82b1848145456b98e2c5b8e6cb1.tar.xz
mpd-21b5cde43ac7c82b1848145456b98e2c5b8e6cb1.zip
ok, optimize memory sage of directorys, by iteratively creating the directories,
this code needs some serious testing: Note: The song name optimization i think is worth it, saves about 200k of ram on my syste, however, having to create directory names iteratively each time we print probably isn't worth the cpu. We only save about 10k of ram for the computer todo alot more work, and the code maybe a little messier git-svn-id: https://svn.musicpd.org/mpd/trunk@2604 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/song.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/song.c b/src/song.c
index 63310b2ff..7d28a3348 100644
--- a/src/song.c
+++ b/src/song.c
@@ -29,7 +29,7 @@
#define SONG_KEY "key: "
#define SONG_FILE "file: "
#define SONG_TIME "Time: "
-#define SONG_MTIME "Mtime: "
+#define SONG_MTIME "mtime: "
#include <stdlib.h>
#include <string.h>
@@ -83,6 +83,7 @@ void freeJustSong(Song * song) {
free(song->url);
if(song->tag) freeMpdTag(song->tag);
free(song);
+ getSongUrl(NULL);
}
SongList * newSongList() {
@@ -118,8 +119,8 @@ void freeSongList(SongList * list) {
void printSongUrl(FILE * fp, Song * song) {
if(song->parentDir) {
- myfprintf(fp, "%s%s/%s\n", SONG_FILE, song->parentDir->utf8name,
- song->url);
+ myfprintf(fp, "%s%s/%s\n", SONG_FILE,
+ getDirectoryPath(song->parentDir), song->url);
}
else {
myfprintf(fp, "%s%s\n", SONG_FILE, song->url);
@@ -299,6 +300,8 @@ Song * songDup(Song * song) {
return ret;
}
+/* pass song = NULL to reset, we do this freeJustSong(), so that if
+ * we free and recreate this memory we make sure to print it correctly*/
char * getSongUrl(Song * song) {
static char * buffer = NULL;
static int bufferSize = 0;
@@ -307,13 +310,18 @@ char * getSongUrl(Song * song) {
int dlen;
int size;
- if(!song->parentDir || !song->parentDir->utf8name) return song->url;
+ if(!song) {
+ lastSong = song;
+ return NULL;
+ }
+
+ if(!song->parentDir || !song->parentDir->name) return song->url;
- /* be careful with this! */
+ /* be careful with this!*/
if(song == lastSong) return buffer;
slen = strlen(song->url);
- dlen = strlen(song->parentDir->utf8name);
+ dlen = strlen(getDirectoryPath(song->parentDir));
size = slen+dlen+2;
@@ -322,7 +330,7 @@ char * getSongUrl(Song * song) {
bufferSize = size;
}
- strcpy(buffer, song->parentDir->utf8name);
+ strcpy(buffer, getDirectoryPath(song->parentDir));
buffer[dlen] = '/';
strcpy(buffer+dlen+1, song->url);