From ca2a1da94937b93e6e482c98e80e28e43f0a5d8f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 12 Jan 2026 18:52:43 +0000 Subject: [PATCH] perf: Optimize statusbar text allocation Replaced heap allocation (malloc/free) with stack buffer in `drawstatusbar`. This removes allocator overhead from a frequent drawing path. Buffer size is aligned with `stext` global definition (1024 bytes). --- .jules/bolt.md | 3 +++ bar.c | 18 +++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..af806dd4 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2026-01-12 - Missing Xinerama Dependency +**Learning:** The environment lacks `Xinerama` headers, preventing the default build configuration from compiling. This is common in minimal environments. +**Action:** When working with X11 window managers, always check for Xinerama support or flags in `config.mk` and be prepared to disable it if headers are missing, or better, ensure dependencies are installed if possible. In this restricted environment, I might need to disable Xinerama in `config.mk` to proceed with verification. diff --git a/bar.c b/bar.c index 8476144a..b5b19122 100644 --- a/bar.c +++ b/bar.c @@ -50,18 +50,14 @@ int drawstatusbar(Monitor *m, int bh, char *stext) { int i; int w; int x; - int len; int cmdcounter; short isCode = 0; - char *text; - char *p; + char text_buf[1024]; + char *text = text_buf; - len = strlen(stext) + 1; - if (!(text = (char *)malloc(sizeof(char) * len))) { - die("malloc"); - } - p = text; - memcpy(text, stext, len); + /* Ensure stext fits in buffer, though stext is already 1024 bytes */ + strncpy(text, stext, sizeof(text_buf)); + text_buf[sizeof(text_buf) - 1] = '\0'; /* compute width of the status text */ w = 0; @@ -88,7 +84,8 @@ int drawstatusbar(Monitor *m, int bh, char *stext) { } else { isCode = 0; } - text = p; + /* Reset text pointer to start of buffer */ + text = text_buf; statuswidth = w; w += 2; /* 1px padding on both sides */ ret = x = m->ww - w - getsystraywidth(); @@ -194,7 +191,6 @@ int drawstatusbar(Monitor *m, int bh, char *stext) { } drw_setscheme(drw, statusscheme); - free(p); return ret; }