hmol233 4 years ago
parent
commit
3531b95d82
1 changed files with 7 additions and 0 deletions
  1. 7 0
      common/buf/buffer.go

+ 7 - 0
common/buf/buffer.go

@@ -26,6 +26,13 @@ type Buffer struct {
 
 // New creates a Buffer with 0 length and 2K capacity.
 func New() *Buffer {
+	buf := pool.Get().([]byte)
+	if cap(buf) >= Size {
+		buf = buf[:Size]
+	} else {
+		buf = make([]byte, Size)
+	}
+
 	return &Buffer{
 		v: buf,
 	}