fix(perf): minor improvement when no indent is found

This commit is contained in:
2024-10-21 01:43:49 +01:00
parent 3878874bbe
commit 84715b90d0

View File

@@ -22,7 +22,7 @@ func Bytes(s string) []byte {
}
// find smallest indent relative to each line-feed
min := 99999999999
min := -1
count := 0
lfs := make([]int, 0, strings.Count(s, "\n"))
@@ -35,7 +35,7 @@ func Bytes(s string) []byte {
if s[i] == lf {
lfs = append(lfs, i)
indent = 0
} else if indent < min {
} else if indent < min || min == -1 {
switch s[i] {
case spc, tab:
indent++
@@ -43,13 +43,17 @@ func Bytes(s string) []byte {
if indent > 0 {
count++
}
if indent < min {
if indent < min || min == -1 {
min = indent
}
}
}
}
if min == -1 {
return []byte(s)
}
// extract each line without indentation
out := make([]byte, 0, len(s)-(min*count))