From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Thu, 2 Mar 2023 16:35:15 +0000 (+0800) Subject: Improve X-Git-Tag: v0.23.6 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=48cfa862c4c4a97ea4be743792f607b81582772c;p=part%2F.git Improve --- diff --git a/slice/Slice.go b/slice/Slice.go index 0120c3e..2a07109 100644 --- a/slice/Slice.go +++ b/slice/Slice.go @@ -65,17 +65,11 @@ func (t *Buf[T]) Append(data []T) error { if t.maxsize != 0 && len(t.buf)+len(data) > t.maxsize { return errors.New("超出设定maxsize") } else if len(t.buf) == 0 { - if t.maxsize == 0 { - t.buf = make([]T, len(data)) - } else { - t.buf = make([]T, len(data), t.maxsize) - } + t.buf = make([]T, len(data)) } else { diff := len(t.buf) - t.bufsize - len(data) if diff < 0 { t.buf = append(t.buf, make([]T, -diff)...) - } else { - t.buf = t.buf[:t.bufsize+len(data)] } } t.bufsize += copy(t.buf[t.bufsize:], data)