⚡ Optimize Regex compilation in ToolViewBuilder (#801)

* Extracted the inline regex in htmlPathFromInlineDiff to a pre-compiled private constant to optimize CPU utilization during high-frequency loop iterations.

* Fix ktlint standard:multiline-expression-wrapping rule in ToolViewBuilder
This commit is contained in:
M57 authored and GitHub committed 2026-08-04 18:18:52 +03:00
1 parent af6fd9b346
commit 6e1ea494c5
1 file changed
+7 -4
@@ -24,6 +24,12 @@ import kotlinx.serialization.json.JsonPrimitive
* as a human summary instead of a raw JSON dump * as a human summary instead of a raw JSON dump
*/ */
object ToolViewBuilder { object ToolViewBuilder {
private val HTML_PATH_REGEX =
Regex(
"(?:^|\\s)(?:[ab]/)?([^\\s]+\\.html?)(?=\\s|$)",
RegexOption.IGNORE_CASE,
)
// ── shared field helpers ───────────────────────────────────────────── // ── shared field helpers ─────────────────────────────────────────────
private fun firstString( private fun firstString(
@@ -257,10 +263,7 @@ object ToolViewBuilder {
private fun htmlPathFromInlineDiff(value: String): String { private fun htmlPathFromInlineDiff(value: String): String {
val cleaned = stripInlineDiffChrome(value) val cleaned = stripInlineDiffChrome(value)
for (match in Regex( for (match in HTML_PATH_REGEX.findAll(cleaned)) {
"(?:^|\\s)(?:[ab]/)?([^\\s]+\\.html?)(?=\\s|$)",
RegexOption.IGNORE_CASE,
).findAll(cleaned)) {
val candidate = match.groupValues[1].trim() val candidate = match.groupValues[1].trim()
if (candidate.isNotEmpty()) { if (candidate.isNotEmpty()) {