优化代码

This commit is contained in:
刘祥超
2021-12-13 15:31:03 +08:00
parent 173175a248
commit 28e93c05a2
2 changed files with 42 additions and 8 deletions

View File

@@ -31,7 +31,17 @@ func ParseVariables(source string, replacer func(varName string) (value string))
return source
}
// replace
// 只有一个占位时,我们快速返回
if len(holders) == 1 {
var h = holders[0]
holder, ok := h.(VariableHolder)
if ok {
return replacer(string(holder))
}
return source
}
// 多个占位时使用Builder
result := strings.Builder{}
for _, h := range holders {
holder, ok := h.(VariableHolder)