Refactor SAlloc
This commit is contained in:
+5
-8
@@ -39,6 +39,8 @@ add_chunk(SAlloc *p, Chunk *c)
|
|||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
|
p->current->next = c;
|
||||||
|
|
||||||
c->next = NULL;
|
c->next = NULL;
|
||||||
c->firstfree = 0;
|
c->firstfree = 0;
|
||||||
|
|
||||||
@@ -73,16 +75,11 @@ uc_new_salloc(size_t chunksz)
|
|||||||
if (first == NULL) {
|
if (first == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
p = (SAlloc *)&first->data.data[0];
|
first->next = NULL;
|
||||||
first->firstfree = sizeof *p;
|
first->firstfree = sizeof *p;
|
||||||
|
|
||||||
|
p = (SAlloc *)&first->data.data[0];
|
||||||
p->chunksz = chunksz;
|
p->chunksz = chunksz;
|
||||||
p->current = NULL;
|
|
||||||
|
|
||||||
if ((first = add_chunk(p, first)) == NULL) {
|
|
||||||
free(p);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
p->first = p->current = first;
|
p->first = p->current = first;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
Reference in New Issue
Block a user