From de69fd858bf212bfabf7ce47fdf46d9c19dc3b06 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 26 Mar 2021 06:24:59 -0400 Subject: [PATCH] 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. --- src/lib/internal.h | 1 + src/lib/render.c | 4 ++-- src/lib/sprite.c | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 7d278c7d9..dbb5e7c16 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -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; diff --git a/src/lib/render.c b/src/lib/render.c index 698688526..2efda0464 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -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; diff --git a/src/lib/sprite.c b/src/lib/sprite.c index b16b6a636..20088bab3 100644 --- a/src/lib/sprite.c +++ b/src/lib/sprite.c @@ -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;