Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance issue with subproperties #2355

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions internal/ini/literal_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ func newLitToken(b []rune) (Token, int, error) {
return token, n, err
}

// replace with slices.Contains when Go 1.21
// is min supported Go version in the SDK
func containsRune(runes []rune, val rune) bool {
for i := range runes {
if val == runes[i] {
return true
}
}
return false
}

func isSubProperty(runes []rune) bool {
// needs at least
// (1) newline (2) whitespace (3) literal
Expand All @@ -141,10 +152,7 @@ func isSubProperty(runes []rune) bool {
}

// must have an equal expression
split := strings.FieldsFunc(string(runes), func(r rune) bool {
return isOp([]rune{r})
})
if len(split) < 2 {
if !containsRune(runes, '=') && !containsRune(runes, ':') {
return false
}

Expand All @@ -156,7 +164,6 @@ func isSubProperty(runes []rune) bool {
if err != nil {
return false
}

// whitespace must follow newline
return isWhitespace(runes[n])
}
Expand Down
Loading