From 57db8dfe239d056c7f0020549218fb7ac201aa1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=A9=E3=82=A4=E3=83=B3?= <53483352+Nep-Timeline@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:36:43 +0800 Subject: [PATCH] Chore: Something update from clash (#639) Chore: add alive for proxy api Improve: alloc using make if alloc size > 65536 --- adapter/adapter.go | 1 + common/pool/alloc.go | 25 +++++++++++++++++-------- common/pool/alloc_test.go | 6 +++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index 32b6bae0..20de5f29 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -176,6 +176,7 @@ func (p *Proxy) MarshalJSON() ([]byte, error) { _ = json.Unmarshal(inner, &mapping) mapping["history"] = p.DelayHistory() mapping["extra"] = p.ExtraDelayHistory() + mapping["alive"] = p.Alive() mapping["name"] = p.Name() mapping["udp"] = p.SupportUDP() mapping["xudp"] = p.SupportXUDP() diff --git a/common/pool/alloc.go b/common/pool/alloc.go index 25f79897..5722b047 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<