From 2089a2ece4824f2e2b8c19e8d620790afdb438d1 Mon Sep 17 00:00:00 2001 From: Rueian Date: Sat, 15 Jan 2022 11:11:04 +0800 Subject: [PATCH] refactor: len(c.cs.s) > 0 should be guaranteed --- internal/cmds/cmds.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/internal/cmds/cmds.go b/internal/cmds/cmds.go index 5660a082..be0da3a3 100644 --- a/internal/cmds/cmds.go +++ b/internal/cmds/cmds.go @@ -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 {