From 43e63bcc244c8c02b18d3e653996b19e147bbbf1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 19 Sep 2026 09:01:45 +0200 Subject: [PATCH] Return early from WithPadding when there is nothing to pad to A caller that asks for a padding of zero gets its string back unchanged, but only after WithPadding has measured it, and measuring means a Decolorise lookup and a width scan over the result. A later commit pads four cells of every commit in the list, and asks for a padding of zero for all four whenever no rebase or bisect is in progress and the date column is hidden, so make that case cost nothing. Co-Authored-By: Claude Opus 5 (1M context) --- pkg/utils/formatting.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/utils/formatting.go b/pkg/utils/formatting.go index 080f58f87..4fb1702f4 100644 --- a/pkg/utils/formatting.go +++ b/pkg/utils/formatting.go @@ -36,6 +36,12 @@ func StringWidth(s string) int { // WithPadding pads a string as much as you want func WithPadding(str string, padding int, alignment Alignment) string { + if padding <= 0 { + // Nothing to pad to, and measuring the string isn't free: Decolorise + // compiles a regex whenever it is called with a string it hasn't cached. + return str + } + uncoloredStr := Decolorise(str) width := StringWidth(uncoloredStr) if padding < width {