aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorN-R-K <nrk@disroot.org>2022-06-01 03:40:49 +0200
committerGitHub <noreply@github.com>2022-06-01 03:40:49 +0200
commit364c3d6f019a26e68f2bfb9594d6bc599a947be2 (patch)
treef72a5a8153290c684c801154d87045370c7e9000
parent57ff8afe028267f71111d28278770fc9bac9baff (diff)
downloadnsxiv-364c3d6f019a26e68f2bfb9594d6bc599a947be2.tar.zst
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
-rw-r--r--nsxiv.h5
-rw-r--r--window.c16
2 files changed, 8 insertions, 13 deletions
diff --git a/nsxiv.h b/nsxiv.h
index 55041bd..1b11cba 100644
--- a/nsxiv.h
+++ b/nsxiv.h
@@ -367,11 +367,6 @@ spawn_t spawn(const char*, char *const [], unsigned int);
#endif
enum {
- BAR_L_LEN = 512,
- BAR_R_LEN = 64
-};
-
-enum {
ATOM_WM_DELETE_WINDOW,
ATOM__NET_WM_NAME,
ATOM__NET_WM_ICON_NAME,
diff --git a/window.c b/window.c
index 69c7b66..1e1ac59 100644
--- a/window.c
+++ b/window.c
@@ -106,11 +106,13 @@ void win_init(win_t *win)
{
win_env_t *e;
const char *win_bg, *win_fg, *mrk_fg;
+ char *res_man;
+ XrmDatabase db;
#if HAVE_LIBFONTS
const char *bar_fg, *bar_bg, *f;
+
+ static char lbuf[512 + 3], rbuf[64 + 3];
#endif
- char *res_man;
- XrmDatabase db;
memset(win, 0, sizeof(win_t));
@@ -148,13 +150,11 @@ void win_init(win_t *win)
f = win_res(db, RES_CLASS ".bar.font", DEFAULT_FONT);
win_init_font(e, f);
- win->bar.l.size = BAR_L_LEN;
- win->bar.r.size = BAR_R_LEN;
+ win->bar.l.buf = lbuf;
+ win->bar.r.buf = rbuf;
/* 3 padding bytes needed by utf8_decode */
- win->bar.l.buf = emalloc(win->bar.l.size + 3);
- win->bar.l.buf[0] = '\0';
- win->bar.r.buf = emalloc(win->bar.r.size + 3);
- win->bar.r.buf[0] = '\0';
+ win->bar.l.size = sizeof(lbuf) - 3;
+ win->bar.r.size = sizeof(rbuf) - 3;
win->bar.h = options->hide_bar ? 0 : barheight;
win->bar.top = TOP_STATUSBAR;
#endif /* HAVE_LIBFONTS */