From d9b4fdde8812fe3f134d97d8fbf541ac15da8529 Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Sun, 5 Mar 2023 00:16:10 +0800 Subject: [PATCH] Remove --- slice/Slice.go | 16 ---------------- slice/Slice_test.go | 30 ------------------------------ 2 files changed, 46 deletions(-) diff --git a/slice/Slice.go b/slice/Slice.go index 755b7a2..5d98d42 100644 --- a/slice/Slice.go +++ b/slice/Slice.go @@ -159,19 +159,3 @@ func (t *Buf[T]) GetCopyBuf() (buf []T) { copy(buf, t.buf[:t.bufsize]) return } - -// *Need to lock when processing buf or Make sure buf only processing by AppendBufCopy -// -// *Not use b = make() to avoid pointer change -func (t *Buf[T]) AppendBufCopy(buf *[]T) { - t.l.RLock() - defer t.l.RUnlock() - - origin := len(*buf) - if origin == 0 { - *buf = make([]T, t.bufsize) - } else { - *buf = append(*buf, make([]T, t.bufsize)...) - } - copy((*buf)[origin:], t.buf[:t.bufsize]) -} diff --git a/slice/Slice_test.go b/slice/Slice_test.go index c610c68..a093095 100644 --- a/slice/Slice_test.go +++ b/slice/Slice_test.go @@ -3,7 +3,6 @@ package part import ( "bytes" "testing" - "unsafe" ) func TestXxx(t *testing.T) { @@ -80,32 +79,3 @@ func TestXxx2(t *testing.T) { t.Fatal() } } - -func TestXxx3(t *testing.T) { - var c = New[byte]() - var b []byte - var bp = unsafe.Pointer(&b) - c.Append([]byte("12345")) - c.Append([]byte("67890")) - c.AppendBufCopy(&b) - c.Reset() - if !bytes.Equal(b, []byte("1234567890")) { - t.Fatal(string(b)) - } - b = []byte{} - c.Append([]byte("abc")) - c.Append([]byte("defg")) - c.AppendBufCopy(&b) - c.Reset() - if !bytes.Equal(b, []byte("abcdefg")) || unsafe.Pointer(&b) != bp { - t.Fatal() - } - b = b[:0] - c.Append([]byte("akjsdhfaksdjhf")) - c.Append([]byte("9834719203857")) - c.AppendBufCopy(&b) - c.Reset() - if !bytes.Equal(b, []byte("akjsdhfaksdjhf9834719203857")) || unsafe.Pointer(&b) != bp { - t.Fatal() - } -} -- 2.39.2