From 48cfa862c4c4a97ea4be743792f607b81582772c Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Fri, 3 Mar 2023 00:35:15 +0800 Subject: [PATCH] Improve --- slice/Slice.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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) -- 2.39.2