cell_load(): recycle when possible #473

This commit is contained in:
nick black 2020-04-14 09:49:33 -04:00 committed by Nick Black
parent 45b821645a
commit a7d9220f21

View File

@ -1324,10 +1324,10 @@ int ncplane_cursor_at(const ncplane* n, cell* c, char** gclust){
}
int cell_load(ncplane* n, cell* c, const char* gcluster){
cell_release(n, c);
int bytes;
int cols;
if((bytes = utf8_egc_len(gcluster, &cols)) >= 0 && bytes <= 1){
cell_release(n, c);
c->channels &= ~CELL_WIDEASIAN_MASK;
c->gcluster = *gcluster;
return !!c->gcluster;
@ -1337,6 +1337,13 @@ int cell_load(ncplane* n, cell* c, const char* gcluster){
}else{
c->channels &= ~CELL_WIDEASIAN_MASK;
}
if(!cell_simple_p(c)){
if(strcmp(gcluster, cell_extended_gcluster(n, c)) == 0){
return bytes; // reduce, reuse, recycle
}else{
cell_release(n, c);
}
}
int eoffset = egcpool_stash(&n->pool, gcluster, bytes);
if(eoffset < 0){
return -1;