try to avoid unneeded malloc

This commit is contained in:
Vitor Santos Costa
2016-12-10 01:04:37 -06:00
parent 6e2d2628c6
commit d81e077cbe
3 changed files with 64 additions and 27 deletions

View File

@@ -70,6 +70,33 @@ int pop_text_stack(int i) {
return lvl;
}
void *protected_pop_text_stack(int i, void *protected, bool tmp,
size_t sz USES_REGS) {
void *out = protected;
int lvl = LOCAL_TextBuffer->lvl;
while (lvl > i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
while (p) {
struct mblock *np = p->next;
if (p + 1 == protected) {
if (tmp)
out = LOCAL_FileNameBuf;
else
out = p;
memcpy(out, protected, sz);
} else {
free(p);
}
p = np;
}
LOCAL_TextBuffer->first[lvl] = NULL;
LOCAL_TextBuffer->last[lvl] = NULL;
lvl--;
}
LOCAL_TextBuffer->lvl = lvl;
return out;
}
// void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; }
void *Malloc(size_t sz USES_REGS) {