Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f893f03

Browse files
committed
remove allocator
1 parent 795b969 commit f893f03

4 files changed

Lines changed: 1 addition & 154 deletions

File tree

alloc.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

alloc_test.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (s *Session) recvLoop() {
340340
s.streamLock.Unlock()
341341
case cmdPSH:
342342
if hdr.Length() > 0 {
343-
newbuf := defaultAllocator.Get(int(hdr.Length()))
343+
newbuf := make([]byte, hdr.Length())
344344
if written, err := io.ReadFull(s.conn, newbuf); err == nil {
345345
s.streamLock.Lock()
346346
if stream, ok := s.streams[sid]; ok {

stream.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ type Stream struct {
1616
sess *Session
1717

1818
buffers [][]byte
19-
heads [][]byte // slice heads kept for recycle
2019

2120
bufferLock sync.Mutex
2221
frameSize int
@@ -71,9 +70,6 @@ func (s *Stream) Read(b []byte) (n int, err error) {
7170
if len(s.buffers[0]) == 0 {
7271
s.buffers[0] = nil
7372
s.buffers = s.buffers[1:]
74-
// full recycle
75-
defaultAllocator.Put(s.heads[0])
76-
s.heads = s.heads[1:]
7773
}
7874
}
7975
s.bufferLock.Unlock()
@@ -97,13 +93,11 @@ func (s *Stream) WriteTo(w io.Writer) (n int64, err error) {
9793
if len(s.buffers) > 0 {
9894
buf = s.buffers[0]
9995
s.buffers = s.buffers[1:]
100-
s.heads = s.heads[1:]
10196
}
10297
s.bufferLock.Unlock()
10398

10499
if buf != nil {
105100
nw, ew := w.Write(buf)
106-
defaultAllocator.Put(buf)
107101
s.sess.returnTokens(len(buf))
108102
if nw > 0 {
109103
n += int64(nw)
@@ -262,7 +256,6 @@ func (s *Stream) RemoteAddr() net.Addr {
262256
func (s *Stream) pushBytes(buf []byte) (written int, err error) {
263257
s.bufferLock.Lock()
264258
s.buffers = append(s.buffers, buf)
265-
s.heads = append(s.heads, buf)
266259
s.bufferLock.Unlock()
267260
return
268261
}
@@ -272,10 +265,8 @@ func (s *Stream) recycleTokens() (n int) {
272265
s.bufferLock.Lock()
273266
for k := range s.buffers {
274267
n += len(s.buffers[k])
275-
defaultAllocator.Put(s.heads[k])
276268
}
277269
s.buffers = nil
278-
s.heads = nil
279270
s.bufferLock.Unlock()
280271
return
281272
}

0 commit comments

Comments
 (0)