Krolyxon
Commit 364c3d6

Branches

Refs →

nsxiv364c3d6

avoid doing dynamic allocation for bar buffers (#279)

just use a static buffer since the size is constant and doesn't change.

as opposed to using malloc, this also sets the buffer's initial memory
region to 0 by default.

also remove BAR_{L,R}_LEN from nsxiv.h, not needed after commit b4268fbf38d1f8433c73999466e116e68c7f81e7
Author
N-R-K
Date
2022-06-01 01:40 +0000
Committer
GitHub · 2022-06-01 07:40 +0600
Parent
57ff8af
Commit
364c3d6f019a26e68f2bfb9594d6bc599a947be2

+8 −13

2 files changed

  1. M nsxiv.h +0 −5
  2. M window.c +8 −8
M nsxiv.h View
@@ -366,11 +366,6 @@ spawn_t spawn(const char*, char *const [], unsigned int);
366366 #include <X11/Xft/Xft.h>
367367 #endif
368368
369−enum {
370− BAR_L_LEN = 512,
371− BAR_R_LEN = 64
372−};
373−
374369 enum {
375370 ATOM_WM_DELETE_WINDOW,
376371 ATOM__NET_WM_NAME,
M window.c View
@@ -106,11 +106,13 @@ void win_init(win_t *win)
106106 {
107107 win_env_t *e;
108108 const char *win_bg, *win_fg, *mrk_fg;
109+ char *res_man;
110+ XrmDatabase db;
109111 #if HAVE_LIBFONTS
110112 const char *bar_fg, *bar_bg, *f;
113+
114+ static char lbuf[512 + 3], rbuf[64 + 3];
111115 #endif
112− char *res_man;
113− XrmDatabase db;
114116
115117 memset(win, 0, sizeof(win_t));
116118
@@ -148,13 +150,11 @@ void win_init(win_t *win)
148150 f = win_res(db, RES_CLASS ".bar.font", DEFAULT_FONT);
149151 win_init_font(e, f);
150152
151− win->bar.l.size = BAR_L_LEN;
152− win->bar.r.size = BAR_R_LEN;
153+ win->bar.l.buf = lbuf;
154+ win->bar.r.buf = rbuf;
153155 /* 3 padding bytes needed by utf8_decode */
154− win->bar.l.buf = emalloc(win->bar.l.size + 3);
155− win->bar.l.buf[0] = '\0';
156− win->bar.r.buf = emalloc(win->bar.r.size + 3);
157− win->bar.r.buf[0] = '\0';
156+ win->bar.l.size = sizeof(lbuf) - 3;
157+ win->bar.r.size = sizeof(rbuf) - 3;
158158 win->bar.h = options->hide_bar ? 0 : barheight;
159159 win->bar.top = TOP_STATUSBAR;
160160 #endif /* HAVE_LIBFONTS */