From 3e97ff32bffb13ed97073c19bc62b806c3da1049 Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Wed, 18 Jan 2023 21:15:43 +0800 Subject: [PATCH] fix --- pool/Pool.go | 12 ++++++------ slice/Slice.go | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pool/Pool.go b/pool/Pool.go index f6135e2..edb4c47 100644 --- a/pool/Pool.go +++ b/pool/Pool.go @@ -4,7 +4,7 @@ import ( "sync" ) -type buf[T any] struct { +type Buf[T any] struct { maxsize int newF func() *T validF func(*T) bool @@ -13,8 +13,8 @@ type buf[T any] struct { sync.RWMutex } -func New[T any](NewF func() *T, ValidF func(*T) bool, ReuseF func(*T) *T, maxsize int) *buf[T] { - t := new(buf[T]) +func New[T any](NewF func() *T, ValidF func(*T) bool, ReuseF func(*T) *T, maxsize int) *Buf[T] { + t := new(Buf[T]) t.newF = NewF t.validF = ValidF t.reuseF = ReuseF @@ -22,7 +22,7 @@ func New[T any](NewF func() *T, ValidF func(*T) bool, ReuseF func(*T) *T, maxsiz return t } -func (t *buf[T]) Trim() { +func (t *Buf[T]) Trim() { t.Lock() defer t.Unlock() @@ -35,7 +35,7 @@ func (t *buf[T]) Trim() { } } -func (t *buf[T]) Get() *T { +func (t *Buf[T]) Get() *T { t.Lock() defer t.Unlock() @@ -48,7 +48,7 @@ func (t *buf[T]) Get() *T { return t.newF() } -func (t *buf[T]) Put(item ...*T) { +func (t *Buf[T]) Put(item ...*T) { if len(item) == 0 { return } diff --git a/slice/Slice.go b/slice/Slice.go index b6a42da..3025652 100644 --- a/slice/Slice.go +++ b/slice/Slice.go @@ -6,7 +6,7 @@ import ( "unsafe" ) -type buf[T any] struct { +type Buf[T any] struct { maxsize int bufsize int modified Modified @@ -19,8 +19,8 @@ type Modified struct { t uint64 } -func New[T any](maxsize ...int) *buf[T] { - t := new(buf[T]) +func New[T any](maxsize ...int) *Buf[T] { + t := new(Buf[T]) if len(maxsize) > 0 { t.maxsize = maxsize[0] } @@ -28,7 +28,7 @@ func New[T any](maxsize ...int) *buf[T] { return t } -func (t *buf[T]) Clear() { +func (t *Buf[T]) Clear() { t.Lock() defer t.Unlock() t.buf = nil @@ -36,21 +36,21 @@ func (t *buf[T]) Clear() { t.modified.t += 1 } -func (t *buf[T]) Size() int { +func (t *Buf[T]) Size() int { t.RLock() defer t.RUnlock() return t.bufsize } -func (t *buf[T]) IsEmpty() bool { +func (t *Buf[T]) IsEmpty() bool { t.RLock() defer t.RUnlock() return t.bufsize == 0 } -func (t *buf[T]) Reset() { +func (t *Buf[T]) Reset() { t.Lock() defer t.Unlock() @@ -58,7 +58,7 @@ func (t *buf[T]) Reset() { t.modified.t += 1 } -func (t *buf[T]) Append(data []T) error { +func (t *Buf[T]) Append(data []T) error { t.Lock() defer t.Unlock() @@ -83,7 +83,7 @@ func (t *buf[T]) Append(data []T) error { return nil } -func (t *buf[T]) RemoveFront(n int) error { +func (t *Buf[T]) RemoveFront(n int) error { if n <= 0 { return nil } @@ -103,7 +103,7 @@ func (t *buf[T]) RemoveFront(n int) error { return nil } -func (t *buf[T]) RemoveBack(n int) error { +func (t *Buf[T]) RemoveBack(n int) error { if n <= 0 { return nil } @@ -124,21 +124,21 @@ func (t *buf[T]) RemoveBack(n int) error { } // unsafe -func (t *buf[T]) SetModified() { +func (t *Buf[T]) SetModified() { t.Lock() defer t.Unlock() t.modified.t += 1 } -func (t *buf[T]) GetModified() Modified { +func (t *Buf[T]) GetModified() Modified { t.RLock() defer t.RUnlock() return t.modified } -func (t *buf[T]) HadModified(mt Modified) (same bool, err error) { +func (t *Buf[T]) HadModified(mt Modified) (same bool, err error) { t.RLock() defer t.RUnlock() @@ -150,14 +150,14 @@ func (t *buf[T]) HadModified(mt Modified) (same bool, err error) { } // unsafe -func (t *buf[T]) GetPureBuf() (buf []T) { +func (t *Buf[T]) GetPureBuf() (buf []T) { t.RLock() defer t.RUnlock() return t.buf[:t.bufsize] } -func (t *buf[T]) GetCopyBuf() (buf []T) { +func (t *Buf[T]) GetCopyBuf() (buf []T) { t.RLock() defer t.RUnlock() -- 2.39.2