fwrite vs ncputs

theoretically, fwrite() could get better performance than
fputs() due to knowing the length of its input buffer. i
didn't see any perf change beyond noise, but who knows.
This commit is contained in:
nick black 2021-03-26 06:24:59 -04:00
parent 465390f5e1
commit de69fd858b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 4 additions and 2 deletions

View File

@ -58,6 +58,7 @@ typedef enum {
// protocol, we just have to rewrite them.
typedef struct sprixel {
char* glyph; // glyph; can be quite large
int glyphlen;
uint32_t id; // embedded into glusters field of nccell, 24 bits
struct ncplane* n; // associated ncplane
sprixel_e invalidated;

View File

@ -723,7 +723,7 @@ term_esc_rgb(FILE* out, bool foreground, unsigned r, unsigned g, unsigned b){
}
rgbbuf[offset++] = 'm';
rgbbuf[offset] = '\0';
if(ncfputs(rgbbuf, out) == EOF){
if(fwrite(rgbbuf, offset, 1, out) != 1){
return -1;
}
return 0;
@ -971,7 +971,7 @@ rasterize_sprixels(notcurses* nc, const ncpile* p, FILE* out){
if(goto_location(nc, out, y + nc->stdplane->absy, x + nc->stdplane->absx)){
return -1;
}
if(ncfputs(s->glyph, out) < 0){
if(fwrite(s->glyph, s->glyphlen, 1, out) != 1){
return -1;
}
s->invalidated = SPRIXEL_NOCHANGE;

View File

@ -39,6 +39,7 @@ sprixel* sprixel_create(ncplane* n, const char* s, int bytes, int placey, int pl
free(ret);
return NULL;
}
ret->glyphlen = bytes;
ret->tacache = tacache;
ret->invalidated = SPRIXEL_INVALIDATED;
ret->n = n;