Skip to content

Commit 2d08573

Browse files
committed
tfutil: preallocate slice
1 parent 971e5e1 commit 2d08573

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

internal/tfutil/tfutil.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ func TFValueToString(val attr.Value) string {
3535
// TFListToStringSlice converts a types.List to a []string by calling
3636
// tfValueToString on each element.
3737
func TFListToStringSlice(l types.List) []string {
38-
var ss []string
39-
for _, el := range l.Elements() {
40-
ss = append(ss, TFValueToString(el))
38+
els := l.Elements()
39+
ss := make([]string, len(els))
40+
for idx, el := range els {
41+
ss[idx] = TFValueToString(el)
4142
}
4243
return ss
4344
}
4445

4546
// TFMapToStringMap converts a types.Map to a map[string]string by calling
4647
// tfValueToString on each element.
4748
func TFMapToStringMap(m types.Map) map[string]string {
48-
res := make(map[string]string)
49-
for k, v := range m.Elements() {
49+
els := m.Elements()
50+
res := make(map[string]string, len(els))
51+
for k, v := range els {
5052
res[k] = TFValueToString(v)
5153
}
5254
return res

0 commit comments

Comments
 (0)