fbuf: implement growth #1977

dankamongmen/iterm2complete
nick black 3 years ago committed by nick black
parent 98559b1911
commit 07b7e0c13f

@ -21,11 +21,7 @@ extern "C" {
typedef struct fbuf {
uint64_t size;
uint64_t used;
#ifdef __MINGW64__
LPVOID buf;
#else
char* buf;
#endif
} fbuf;
// header-only so that we can test it from notcurses-tester
@ -139,16 +135,7 @@ fbuf_init_small(fbuf* f){
return fbuf_initgrow(f, 1);
}
// prepare f with an initial buffer.
static inline int
fbuf_init_small(fbuf* f){
f->used = 0;
f->size = 0;
f->buf = NULL;
return fbuf_grow(f, 0);
}
// prepare f with an initial buffer.
// prepare f with a large initial buffer.
static inline int
fbuf_init(fbuf* f){
f->used = 0;
@ -163,12 +150,6 @@ fbuf_reset(fbuf* f){
f->used = 0;
}
// reset usage, but don't shrink the buffer or anything
static inline void
fbuf_reset(fbuf* f){
f->used = 0;
}
static inline int
fbuf_putc(fbuf* f, char c){
if(fbuf_grow(f, 1)){

@ -218,7 +218,9 @@ init_sprixel_animation(sprixel* s){
if(s->animating){
return 0;
}
fbuf_free(&s->glyph);
if(fbuf_init(&s->glyph)){
return -1;
}
s->animating = true;
return 0;
}

@ -117,30 +117,35 @@ void sprixel_invalidate(sprixel* s, int y, int x){
sprixel* sprixel_alloc(const tinfo* ti, ncplane* n, int dimy, int dimx){
sprixel* ret = malloc(sizeof(sprixel));
if(ret){
memset(ret, 0, sizeof(*ret));
ret->n = n;
ret->dimy = dimy;
ret->dimx = dimx;
ret->id = ++sprixelid_nonce;
if(ret->id >= 0x1000000){
ret->id = 1;
sprixelid_nonce = 1;
}
if(ret == NULL){
return NULL;
}
memset(ret, 0, sizeof(*ret));
if(fbuf_init(&ret->glyph)){
free(ret);
return NULL;
}
ret->n = n;
ret->dimy = dimy;
ret->dimx = dimx;
ret->id = ++sprixelid_nonce;
if(ret->id >= 0x1000000){
ret->id = 1;
sprixelid_nonce = 1;
}
//fprintf(stderr, "LOOKING AT %p (p->n = %p)\n", ret, ret->n);
ret->cellpxy = ti->cellpixy;
ret->cellpxx = ti->cellpixx;
if(ncplane_pile(ret->n)){ // rendered mode
ncpile* np = ncplane_pile(ret->n);
if( (ret->next = np->sprixelcache) ){
ret->next->prev = ret;
}
np->sprixelcache = ret;
ret->prev = NULL;
//fprintf(stderr, "%p %p %p\n", nc->sprixelcache, ret, nc->sprixelcache->next);
}else{ // ncdirect case
ret->next = ret->prev = NULL;
ret->cellpxy = ti->cellpixy;
ret->cellpxx = ti->cellpixx;
if(ncplane_pile(ret->n)){ // rendered mode
ncpile* np = ncplane_pile(ret->n);
if( (ret->next = np->sprixelcache) ){
ret->next->prev = ret;
}
np->sprixelcache = ret;
ret->prev = NULL;
//fprintf(stderr, "%p %p %p\n", nc->sprixelcache, ret, nc->sprixelcache->next);
}else{ // ncdirect case
ret->next = ret->prev = NULL;
}
return ret;
}

Loading…
Cancel
Save