Skip to content

Commit e15e65a

Browse files
committed
refactor(reflect): use a string builder instead
1 parent 2d02e8d commit e15e65a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/template/reflect.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ func deepGetImpl(v reflect.Value, path []string) interface{} {
4747
}
4848

4949
// If the first part of the path is not a key in the map, we try to find a valid key by joining the path parts
50-
for i := 2; i <= len(path); i++ {
51-
joinedPath := strings.Join(path[0:i], ".")
50+
var builder strings.Builder
51+
for i, pathPart := range path {
52+
if i > 0 {
53+
builder.WriteString(".")
54+
}
55+
builder.WriteString(pathPart)
56+
joinedPath := builder.String()
57+
5258
if mapValue := v.MapIndex(reflect.ValueOf(joinedPath)); mapValue.IsValid() {
5359
if i == len(path) {
5460
return mapValue.Interface()
5561
}
56-
return deepGetImpl(mapValue, path[i:])
62+
return deepGetImpl(mapValue, path[i+1:])
5763
}
5864
}
5965

0 commit comments

Comments
 (0)