From 7b784859d09d0e3e875b03a03bec16a9555aa27c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 02:47:32 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Cache=20regex=20to=20preven?= =?UTF-8?q?t=20recompilation=20on=20every=20extract=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extracts the `\s+` regex allocation from within the `HintExtractor.extract` method to a static `WHITESPACE` property to eliminate recompilation overhead on each invocation. Co-authored-by: himattm <6266621+himattm@users.noreply.github.com> --- .../src/commonMain/kotlin/halogen/engine/HintExtractor.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/halogen-engine/src/commonMain/kotlin/halogen/engine/HintExtractor.kt b/halogen-engine/src/commonMain/kotlin/halogen/engine/HintExtractor.kt index c5cb8cb..d18248b 100644 --- a/halogen-engine/src/commonMain/kotlin/halogen/engine/HintExtractor.kt +++ b/halogen-engine/src/commonMain/kotlin/halogen/engine/HintExtractor.kt @@ -15,6 +15,11 @@ internal object HintExtractor { private val ID_PATTERN = Regex("""^[0-9a-f]{8,}$""", RegexOption.IGNORE_CASE) private val NUMERIC_ONLY = Regex("""^\d+$""") + // ⚡ Bolt: Cache regex to prevent recompilation on every extract call. + // Expected impact: Eliminates regex allocation/compilation overhead per extraction, + // saving memory and execution time in a hot path. + private val WHITESPACE = Regex("""\s+""") + fun extract(key: String): String? { if (key.isBlank()) return null @@ -36,7 +41,7 @@ internal object HintExtractor { cleaned = cleaned.replace('_', ' ').replace('-', ' ') // Normalize whitespace - cleaned = cleaned.trim().replace(Regex("""\s+"""), " ") + cleaned = cleaned.trim().replace(WHITESPACE, " ") if (cleaned.isBlank()) return null