mirror of
https://github.com/fumiama/orbyte.git
synced 2026-06-10 13:10:32 +08:00
feat: add ref counter
This commit is contained in:
@@ -30,13 +30,15 @@ func TestBytesSlice(t *testing.T) {
|
||||
buf := make([]byte, b.Len())
|
||||
copy(buf, b.Bytes())
|
||||
// test normal slice
|
||||
x := b.SliceFrom(5).SliceTo(i - 5 - 5)
|
||||
y := b.SliceFrom(5)
|
||||
x := y.SliceTo(i - 5 - 5)
|
||||
if !bytes.Equal(buf[5:i-5], x.Bytes()) {
|
||||
t.Log("exp:", hex.EncodeToString(buf[5:i-5]))
|
||||
t.Log("got:", hex.EncodeToString(x.Bytes()))
|
||||
t.Fatal("index", i, "unexpected")
|
||||
}
|
||||
x.manualDestroy()
|
||||
y.manualDestroy()
|
||||
// test trans slice
|
||||
b = b.Trans().SliceFrom(5).SliceTo(i - 5 - 5)
|
||||
if !bytes.Equal(buf[5:i-5], b.Bytes()) {
|
||||
@@ -103,19 +105,25 @@ func TestBytesCopy(t *testing.T) {
|
||||
buf := make([]byte, 4096)
|
||||
rand.Read(buf)
|
||||
for i := 10; i < 4096; i++ {
|
||||
b := ParseBytes(buf...).Slice(5, i-5).Copy()
|
||||
a := ParseBytes(buf...)
|
||||
x := a.Slice(5, i-5)
|
||||
b := x.Copy()
|
||||
if b.Len() != i-10 {
|
||||
t.Fatal("index", i, "excpet len", i, "but got", b.Len())
|
||||
}
|
||||
rand.Read(b.Bytes())
|
||||
t.Log("org:", hex.EncodeToString(buf[:i]))
|
||||
t.Log("new:", hex.EncodeToString(b.Bytes()))
|
||||
// t.Log("org:", hex.EncodeToString(buf[:i]))
|
||||
// t.Log("new:", hex.EncodeToString(b.Bytes()))
|
||||
if bytes.Equal(b.Bytes(), buf[:i]) {
|
||||
t.Fatal("index", i, "unexpected")
|
||||
}
|
||||
b.manualDestroy()
|
||||
x.manualDestroy()
|
||||
a.manualDestroy()
|
||||
}
|
||||
runtime.GC()
|
||||
runtime.Gosched()
|
||||
runtime.GC()
|
||||
out, in := bufferPool.p.CountItems()
|
||||
t.Log(out, in)
|
||||
if out != 0 {
|
||||
@@ -125,7 +133,7 @@ func TestBytesCopy(t *testing.T) {
|
||||
|
||||
func TestBytesTransMultithread(t *testing.T) {
|
||||
wg := sync.WaitGroup{}
|
||||
for i := 0; i < 4096; i++ {
|
||||
for i := 0; i < 2048; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
Reference in New Issue
Block a user