Skip to content

Commit

Permalink
refactor: len(c.cs.s) > 0 should be guaranteed
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Jan 15, 2022
1 parent 5407877 commit 2089a2e
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions internal/cmds/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,16 @@ func (c *Cacheable) CacheKey() (key, command string) {
if len(c.cs.s) == 2 {
return c.cs.s[1], c.cs.s[0]
}

length := 0
for i, v := range c.cs.s {
if i == 1 {
continue
}
for _, v := range c.cs.s[1:] { // len(c.cs.s) > 0 should be guaranteed
length += len(v)
}
sb := strings.Builder{}
sb.Grow(length)
for i, v := range c.cs.s {
if i == 1 {
key = v
} else {
sb.WriteString(v)
}
for _, v := range c.cs.s[1:] {
sb.WriteString(v)
}
return key, sb.String()
return c.cs.s[0], sb.String()
}

func NewCompleted(ss []string) Completed {
Expand Down

0 comments on commit 2089a2e

Please sign in to comment.