From cad9ffd2b0fe31f39f4c97519487bc2c5033b887 Mon Sep 17 00:00:00 2001 From: Nikita Krasnikov Date: Wed, 20 Sep 2023 19:56:19 +0300 Subject: [PATCH] Fix unnecessary function call ReplaceAcronymRunes --- strcase.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/strcase.go b/strcase.go index e7861df..6e201d9 100644 --- a/strcase.go +++ b/strcase.go @@ -187,7 +187,13 @@ func ParseRunes(rs []rune) [][]rune { func camelCase(runes []rune, upper bool, replaceAcronym bool) []rune { camelCase := make([]rune, 0, len(runes)) for i, rs := range ParseRunes(runes) { - if nRs, ok := ReplaceAcronymRunes(rs); replaceAcronym && ok { + var nRs []rune + var foundReplace bool + if replaceAcronym { + nRs, foundReplace = ReplaceAcronymRunes(rs) + } + + if foundReplace { rs = nRs } else if i == 0 { if upper { @@ -267,12 +273,16 @@ func ReplaceAcronymsRunes(runeWords [][]rune) [][]rune { } func ReplaceAcronymRunes(runeWord []rune) ([]rune, bool) { + return replaceAcronymRunes(runeWord, false) +} + +func replaceAcronymRunes(runeWord []rune, exit bool) ([]rune, bool) { if acr, ok := acrMap.Load(string(runeWord)); ok { if acr, ok := acr.([]rune); ok { return acr, true } - } else if !isLower(runeWord) { - return ReplaceAcronymRunes(toLowerRunes(runeWord)) + } else if !exit { + return replaceAcronymRunes(toLowerRunes(runeWord), true) } return runeWord, false }