Update module.go

making code more similar to https://github.com/hashicorp/terraform/blob/main/internal/addrs/module_instance.go
This commit is contained in:
Dennis Gursky 2022-06-22 06:29:57 -07:00 committed by GitHub
parent 8a694e81ff
commit 2c1b1f3aa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,21 +33,22 @@ func (m Module) String() string {
if len(m) == 0 {
return ""
}
size := 0
for _, s := range m {
size += len(s)
// Calculate necessary space.
l := 0
for _, step := range m {
l += len(step)
}
var sb strings.Builder
// 8 is len("module.") + len(".")
sb.Grow(8*len(m) + size)
for i, s := range m {
sb.WriteString("module.")
sb.WriteString(s)
if i != len(m)-1 {
sb.WriteString(".")
}
buf := strings.Builder{}
// 8 is len(".module.") which separates entries.
buf.Grow(l + len(m)*8)
sep := ""
for _, step := range m {
buf.WriteString(sep)
buf.WriteString("module.")
buf.WriteString(step)
sep = "."
}
return sb.String()
return buf.String()
}
func (m Module) Equal(other Module) bool {