From 46ef08f4931f24b0afeb12064fa13db3a27aa745 Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Wed, 18 Jan 2023 22:04:40 +0800 Subject: [PATCH] fix --- slice/Slice.go | 4 +++- slice/Slice_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/slice/Slice.go b/slice/Slice.go index 59f158a..567b463 100644 --- a/slice/Slice.go +++ b/slice/Slice.go @@ -33,6 +33,7 @@ func (t *Buf[T]) Clear() { defer t.Unlock() t.buf = nil t.bufsize = 0 + t.modified.t += 1 } func (t *Buf[T]) Size() int { @@ -54,13 +55,14 @@ func (t *Buf[T]) Reset() { defer t.Unlock() t.bufsize = 0 + t.modified.t += 1 } func (t *Buf[T]) Append(data []T) error { t.Lock() defer t.Unlock() - if len(t.buf)+len(data) > t.maxsize { + 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 { diff --git a/slice/Slice_test.go b/slice/Slice_test.go index b5df02b..435793d 100644 --- a/slice/Slice_test.go +++ b/slice/Slice_test.go @@ -49,4 +49,8 @@ func TestXxx(t *testing.T) { if b.IsEmpty() || b.Size() != 3 { t.Fatal() } + c.Append([]byte("abc")) + if c.IsEmpty() || c.Size() != 3 { + t.Fatal() + } } -- 2.39.2