From 154cb1d1f046ddc48d9ff76183698ef3a72bf01e Mon Sep 17 00:00:00 2001 From: Kr328 Date: Sun, 18 Jun 2023 11:19:35 +0800 Subject: [PATCH] Improve: alloc using make if alloc size > 65536 (#2796) --- common/pool/alloc.go | 25 +++++++++++++++++-------- common/pool/alloc_test.go | 6 +++--- component/process/process_windows.go | 11 ++++++++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/common/pool/alloc.go b/common/pool/alloc.go index 25f7989..f06b1a3 100644 --- a/common/pool/alloc.go +++ b/common/pool/alloc.go @@ -32,23 +32,32 @@ func NewAllocator() *Allocator { // Get a []byte from pool with most appropriate cap func (alloc *Allocator) Get(size int) []byte { - if size <= 0 || size > 65536 { + switch { + case size < 0: + panic("alloc.Get: len out of range") + case size == 0: return nil - } + case size > 65536: + return make([]byte, size) + default: + bits := msb(size) + if size == 1< 65536 { + return nil + } + bits := msb(cap(buf)) - if cap(buf) == 0 || cap(buf) > 65536 || cap(buf) != 1<