Эх сурвалжийг харах

Fix high CPU usage when rendering status bar

Looking up the width of special color setting characters was causing
high CPU usage. Ignore special characters when calculating the width.
Frans Bergman 4 жил өмнө
parent
commit
23937acdbc
1 өөрчлөгдсөн 14 нэмэгдсэн , 1 устгасан
  1. 14 1
      dwm.c

+ 14 - 1
dwm.c

@@ -885,7 +885,20 @@ drawbar(Monitor *m)
 	/* draw status first so it can be overdrawn by tags later */
 	/* draw status first so it can be overdrawn by tags later */
 	if (m == selmon) { /* status is only drawn on selected monitor */
 	if (m == selmon) { /* status is only drawn on selected monitor */
 		drw_setscheme(drw, scheme[SchemeNorm]);
 		drw_setscheme(drw, scheme[SchemeNorm]);
-		sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+		/* calculate text width while ignoring special chars */
+		sw = 0;
+		while (1) {
+			if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
+			ctmp = *ts;
+			*ts = '\0';
+			sw += TEXTW(tp) -lrpad;
+			if (ctmp == '\0') { break; }
+			*ts = ctmp;
+			tp = ++ts;
+		}
+		ts = stext;
+		tp = stext;
+		/* render text */
 		while (1) {
 		while (1) {
 			if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
 			if ((unsigned int)*ts > LENGTH(colors)) { ts++; continue ; }
 			ctmp = *ts;
 			ctmp = *ts;