Skip to content

Commit 36217d1

Browse files
authored
Fix performance issue with subproperties (#2355)
1 parent 5ce58b4 commit 36217d1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "0e1f4e33-13a4-49c8-b223-0d6cc756ef18",
3+
"type": "bugfix",
4+
"description": "Fix subproperty performance regression",
5+
"modules": [
6+
"internal/ini"
7+
]
8+
}

internal/ini/literal_tokens.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ func newLitToken(b []rune) (Token, int, error) {
133133
return token, n, err
134134
}
135135

136+
// replace with slices.Contains when Go 1.21
137+
// is min supported Go version in the SDK
138+
func containsRune(runes []rune, val rune) bool {
139+
for i := range runes {
140+
if val == runes[i] {
141+
return true
142+
}
143+
}
144+
return false
145+
}
146+
136147
func isSubProperty(runes []rune) bool {
137148
// needs at least
138149
// (1) newline (2) whitespace (3) literal
@@ -141,10 +152,7 @@ func isSubProperty(runes []rune) bool {
141152
}
142153

143154
// must have an equal expression
144-
split := strings.FieldsFunc(string(runes), func(r rune) bool {
145-
return isOp([]rune{r})
146-
})
147-
if len(split) < 2 {
155+
if !containsRune(runes, '=') && !containsRune(runes, ':') {
148156
return false
149157
}
150158

@@ -156,7 +164,6 @@ func isSubProperty(runes []rune) bool {
156164
if err != nil {
157165
return false
158166
}
159-
160167
// whitespace must follow newline
161168
return isWhitespace(runes[n])
162169
}

0 commit comments

Comments
 (0)