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.
pull/1471/head
nick black 3 years ago
parent 465390f5e1
commit de69fd858b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

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

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

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

Loading…
Cancel
Save