[sixel_reblit] use new fbuf_chop to avoid copies #2573

This commit is contained in:
nick black 2022-01-29 19:51:30 -05:00 committed by nick black
parent 91183e6044
commit 475b18bd26
2 changed files with 8 additions and 12 deletions

View File

@ -155,6 +155,12 @@ fbuf_reserve(fbuf* f, size_t len){
return 0;
}
static inline void
fbuf_chop(fbuf* f, size_t len){
assert(len <= f->size);
f->used = len;
}
static inline int
fbuf_putc(fbuf* f, char c){
if(fbuf_grow(f, 1)){

View File

@ -1096,20 +1096,10 @@ write_sixel(qstate* qs, fbuf* f, int outy, const sixeltable* stab, int* parse_st
// is redrawn, and annihilated sprixcells still require a glyph to be emitted.
static inline int
sixel_reblit(sprixel* s){
fbuf f;
if(fbuf_init(&f)){
fbuf_chop(&s->glyph, s->parse_start);
if(write_sixel_payload(&s->glyph, s->pixx, s->smap) < 0){
return -1;
}
if(fbuf_putn(&f, s->glyph.buf, s->parse_start) != s->parse_start){
fbuf_free(&f);
return -1;
}
if(write_sixel_payload(&f, s->pixx, s->smap) < 0){
fbuf_free(&f);
return -1;
}
fbuf_free(&s->glyph);
memcpy(&s->glyph, &f, sizeof(f));
change_p2(s->glyph.buf, s->smap->p2);
return 0;
}