comparison src/audacious/playlist.c @ 2633:c079e507869a trunk

[svn] - use a managed heap for playlist entry node allocation.
author nenolod
date Tue, 20 Mar 2007 22:00:11 -0700
parents deb09bfd716b
children 517d13842fe7
comparison
equal deleted inserted replaced
2632:eefcf9c62175 2633:c079e507869a
28 # include "config.h" 28 # include "config.h"
29 #endif 29 #endif
30 30
31 #include "playlist.h" 31 #include "playlist.h"
32 32
33 #include <mowgli.h>
33 #include <glib.h> 34 #include <glib.h>
34 #include <glib/gprintf.h> 35 #include <glib/gprintf.h>
35 #include <stdlib.h> 36 #include <stdlib.h>
36 #include <string.h> 37 #include <string.h>
37 #include <time.h> 38 #include <time.h>
135 136
136 static void playlist_recalc_total_time_nolock(Playlist *); 137 static void playlist_recalc_total_time_nolock(Playlist *);
137 static void playlist_recalc_total_time(Playlist *); 138 static void playlist_recalc_total_time(Playlist *);
138 static gboolean playlist_entry_get_info(PlaylistEntry * entry); 139 static gboolean playlist_entry_get_info(PlaylistEntry * entry);
139 140
141 static mowgli_heap_t *playlist_entry_heap = NULL;
142
140 /* *********************** playlist entry code ********************** */ 143 /* *********************** playlist entry code ********************** */
141 144
142 PlaylistEntry * 145 PlaylistEntry *
143 playlist_entry_new(const gchar * filename, 146 playlist_entry_new(const gchar * filename,
144 const gchar * title, 147 const gchar * title,
145 const gint length, 148 const gint length,
146 InputPlugin * dec) 149 InputPlugin * dec)
147 { 150 {
148 PlaylistEntry *entry; 151 PlaylistEntry *entry;
149 152
150 entry = g_new0(PlaylistEntry, 1); 153 entry = mowgli_heap_alloc(playlist_entry_heap);
151 entry->filename = g_strdup(filename); 154 entry->filename = g_strdup(filename);
152 entry->title = str_to_utf8(title); 155 entry->title = str_to_utf8(title);
153 entry->length = length; 156 entry->length = length;
154 entry->selected = FALSE; 157 entry->selected = FALSE;
155 entry->decoder = dec; 158 entry->decoder = dec;
176 g_free(entry->filename); 179 g_free(entry->filename);
177 180
178 if (entry->title != NULL) 181 if (entry->title != NULL)
179 g_free(entry->title); 182 g_free(entry->title);
180 183
181 g_free(entry); 184 mowgli_heap_free(playlist_entry_heap, entry);
182 } 185 }
183 186
184 static gboolean 187 static gboolean
185 playlist_entry_get_info(PlaylistEntry * entry) 188 playlist_entry_get_info(PlaylistEntry * entry)
186 { 189 {
234 237
235 void 238 void
236 playlist_init(void) 239 playlist_init(void)
237 { 240 {
238 Playlist *initial_pl; 241 Playlist *initial_pl;
242
243 /* create a heap with 1024 playlist entry nodes preallocated. --nenolod */
244 playlist_entry_heap = mowgli_heap_create(sizeof(PlaylistEntry), 1024,
245 BH_NOW);
239 246
240 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */ 247 /* FIXME: is this really necessary? REQUIRE_STATIC_LOCK(playlists); */
241 248
242 initial_pl = playlist_new(); 249 initial_pl = playlist_new();
243 250