ref: 9c7e0ac79703b69d6182ebc1f628ca18eed438e1
parent: ab23e1cbffa4bea97a99d58fea58b13e1958c9f8
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Jan 15 06:27:22 EST 2021
new playlist loader: allocate all metadata once
--- a/zuke.c
+++ b/zuke.c
@@ -715,37 +715,33 @@
{
char *s, *e, *a[5];
Playlist *pl;
- Meta *m;
int plsz;
+ Meta *m;
- m = nil;
- if((pl = calloc(1, sizeof(*pl))) == nil){
-nomem:
+ plsz = 0;
+ for(s = raw; (s = strchr(s, '\n')) != nil; s++){
+ if(*(++s) == '\n')
+ plsz++;
+ }
+
+ if((pl = calloc(1, sizeof(*pl))) == nil || (pl->m = calloc(plsz+1, sizeof(Meta))) == nil){
freeplist(pl);
werrstr("no memory");
return nil;
}
- plsz = 0;
pl->raw = raw;
- for(s = pl->raw;; s = e){
+ for(s = pl->raw, m = pl->m;; s = e){
if((e = strchr(s, '\n')) == nil)
break;
- if(plsz - pl->n < 32){
- plsz = (plsz + 32)*2;
- if((m = realloc(pl->m, sizeof(Meta)*plsz)) == nil)
- goto nomem;
- pl->m = m;
- memset(pl->m+pl->n, 0, sizeof(Meta)*(plsz-pl->n));
- }
- m = pl->m + pl->n;
s += 2;
*e++ = 0;
switch(s[-2]){
case 0:
- if(m->path != nil)
+ if(m->path != nil){
pl->n++;
- m = nil;
+ m++;
+ }
break;
case Pimage:
if(tokenize(s, a, nelem(a)) >= 4){