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
+8 −13
2 files changed
| @@ -366,11 +366,6 @@ spawn_t spawn(const char*, char *const [], unsigned int); | |||
| 366 | 366 | #include <X11/Xft/Xft.h> | |
| 367 | 367 | #endif | |
| 368 | 368 | ||
| 369 | − | enum { | |
| 370 | − | BAR_L_LEN = 512, | |
| 371 | − | BAR_R_LEN = 64 | |
| 372 | − | }; | |
| 373 | − | ||
| 374 | 369 | enum { | |
| 375 | 370 | ATOM_WM_DELETE_WINDOW, | |
| 376 | 371 | ATOM__NET_WM_NAME, | |
| @@ -106,11 +106,13 @@ void win_init(win_t *win) | |||
| 106 | 106 | { | |
| 107 | 107 | win_env_t *e; | |
| 108 | 108 | const char *win_bg, *win_fg, *mrk_fg; | |
| 109 | + | char *res_man; | |
| 110 | + | XrmDatabase db; | |
| 109 | 111 | #if HAVE_LIBFONTS | |
| 110 | 112 | const char *bar_fg, *bar_bg, *f; | |
| 113 | + | ||
| 114 | + | static char lbuf[512 + 3], rbuf[64 + 3]; | |
| 111 | 115 | #endif | |
| 112 | − | char *res_man; | |
| 113 | − | XrmDatabase db; | |
| 114 | 116 | ||
| 115 | 117 | memset(win, 0, sizeof(win_t)); | |
| 116 | 118 | ||
| @@ -148,13 +150,11 @@ void win_init(win_t *win) | |||
| 148 | 150 | f = win_res(db, RES_CLASS ".bar.font", DEFAULT_FONT); | |
| 149 | 151 | win_init_font(e, f); | |
| 150 | 152 | ||
| 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; | |
| 153 | 155 | /* 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; | |
| 158 | 158 | win->bar.h = options->hide_bar ? 0 : barheight; | |
| 159 | 159 | win->bar.top = TOP_STATUSBAR; | |
| 160 | 160 | #endif /* HAVE_LIBFONTS */ | |