Skip to content

Commit

Permalink
backport of commit 2c1b1f3
Browse files Browse the repository at this point in the history
  • Loading branch information
dennygursky committed Jun 22, 2022
1 parent dbb90d0 commit e22c499
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions internal/addrs/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e22c499

Please sign in to comment.