diff options
Diffstat (limited to 'vendor/github.com/bytedance/sonic/internal/rt')
10 files changed, 154 insertions, 221 deletions
diff --git a/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go b/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go index 263bc592f..ec5ea88a0 100644 --- a/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go +++ b/vendor/github.com/bytedance/sonic/internal/rt/base64_amd64.go @@ -1,8 +1,9 @@ -// +build amd64,go1.17,!go1.24 +// +build amd64,go1.17,!go1.25 package rt import ( + _ "unsafe" "github.com/cloudwego/base64x" ) @@ -15,6 +16,29 @@ func DecodeBase64(raw []byte) ([]byte, error) { return ret[:n], nil } -func EncodeBase64(src []byte) string { +func EncodeBase64ToString(src []byte) string { return base64x.StdEncoding.EncodeToString(src) } + +func EncodeBase64(buf []byte, src []byte) []byte { + if len(src) == 0 { + return append(buf, '"', '"') + } + buf = append(buf, '"') + need := base64x.StdEncoding.EncodedLen(len(src)) + if cap(buf) - len(buf) < need { + tmp := make([]byte, len(buf), len(buf) + need*2) + copy(tmp, buf) + buf = tmp + } + base64x.StdEncoding.Encode(buf[len(buf):cap(buf)], src) + buf = buf[:len(buf) + need] + buf = append(buf, '"') + return buf +} + +//go:linkname SubrB64Decode github.com/cloudwego/base64x._subr__b64decode +var SubrB64Decode uintptr + +//go:linkname SubrB64Encode github.com/cloudwego/base64x._subr__b64encode +var SubrB64Encode uintptr diff --git a/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go b/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go index 791f79355..bd3150fe0 100644 --- a/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go +++ b/vendor/github.com/bytedance/sonic/internal/rt/base64_compat.go @@ -1,4 +1,4 @@ -// +build !amd64 !go1.17 go1.24 +// +build !amd64 !go1.17 go1.25 package rt @@ -15,6 +15,23 @@ func DecodeBase64(raw []byte) ([]byte, error) { return ret[:n], nil } -func EncodeBase64(src []byte) string { +func EncodeBase64ToString(src []byte) string { return base64.StdEncoding.EncodeToString(src) } + +func EncodeBase64(buf []byte, src []byte) []byte { + if len(src) == 0 { + return append(buf, '"', '"') + } + buf = append(buf, '"') + need := base64.StdEncoding.EncodedLen(len(src)) + if cap(buf) - len(buf) < need { + tmp := make([]byte, len(buf), len(buf) + need*2) + copy(tmp, buf) + buf = tmp + } + base64.StdEncoding.Encode(buf[len(buf):cap(buf)], src) + buf = buf[:len(buf) + need] + buf = append(buf, '"') + return buf +} diff --git a/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go b/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go index 85c90fc07..bd41afa6c 100644 --- a/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go +++ b/vendor/github.com/bytedance/sonic/internal/rt/fastvalue.go @@ -75,36 +75,6 @@ func (self *GoType) Indirect() bool { return self.KindFlags&F_direct == 0 } -type GoMap struct { - Count int - Flags uint8 - B uint8 - Overflow uint16 - Hash0 uint32 - Buckets unsafe.Pointer - OldBuckets unsafe.Pointer - Evacuate uintptr - Extra unsafe.Pointer -} - -type GoMapIterator struct { - K unsafe.Pointer - V unsafe.Pointer - T *GoMapType - H *GoMap - Buckets unsafe.Pointer - Bptr *unsafe.Pointer - Overflow *[]unsafe.Pointer - OldOverflow *[]unsafe.Pointer - StartBucket uintptr - Offset uint8 - Wrapped bool - B uint8 - I uint8 - Bucket uintptr - CheckBucket uintptr -} - type GoItab struct { it unsafe.Pointer Vt *GoType diff --git a/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go b/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go index 9c670e721..bd3e4ef26 100644 --- a/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go +++ b/vendor/github.com/bytedance/sonic/internal/rt/gcwb.go @@ -1,4 +1,4 @@ -// +build go1.21 +// +build go1.21,!go1.25 /* * Copyright 2021 ByteDance Inc. diff --git a/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go b/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go index 86e14f2b2..f1669df0a 100644 --- a/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go +++ b/vendor/github.com/bytedance/sonic/internal/rt/gcwb_legacy.go @@ -1,4 +1,4 @@ -// +build go1.16,!go1.21 +// +build go1.17,!go1.21 /* * Copyright 2021 ByteDance Inc. diff --git a/vendor/github.com/bytedance/sonic/internal/rt/map_legacy.go b/vendor/github.com/bytedance/sonic/internal/rt/map_legacy.go new file mode 100644 index 000000000..fc8fe5171 --- /dev/null +++ b/vendor/github.com/bytedance/sonic/internal/rt/map_legacy.go @@ -0,0 +1,25 @@ +// +build !go1.24 + +package rt + +import ( + "unsafe" +) + +type GoMapIterator struct { + K unsafe.Pointer + V unsafe.Pointer + T *GoMapType + H unsafe.Pointer + Buckets unsafe.Pointer + Bptr *unsafe.Pointer + Overflow *[]unsafe.Pointer + OldOverflow *[]unsafe.Pointer + StartBucket uintptr + Offset uint8 + Wrapped bool + B uint8 + I uint8 + Bucket uintptr + CheckBucket uintptr +} diff --git a/vendor/github.com/bytedance/sonic/internal/rt/map_nosiwss_go124.go b/vendor/github.com/bytedance/sonic/internal/rt/map_nosiwss_go124.go new file mode 100644 index 000000000..8ecb9878e --- /dev/null +++ b/vendor/github.com/bytedance/sonic/internal/rt/map_nosiwss_go124.go @@ -0,0 +1,28 @@ +//go:build go1.24 && !go1.25 && !goexperiment.swissmap +// +build go1.24,!go1.25,!goexperiment.swissmap + +package rt + +import ( + "unsafe" +) + +type GoMapIterator struct { + K unsafe.Pointer + V unsafe.Pointer + T *GoMapType + H unsafe.Pointer + Buckets unsafe.Pointer + Bptr *unsafe.Pointer + Overflow *[]unsafe.Pointer + OldOverflow *[]unsafe.Pointer + StartBucket uintptr + Offset uint8 + Wrapped bool + B uint8 + I uint8 + Bucket uintptr + CheckBucket uintptr + // different from go1.23 + ClearSeq uint64 +} diff --git a/vendor/github.com/bytedance/sonic/internal/rt/map_siwss_go124.go b/vendor/github.com/bytedance/sonic/internal/rt/map_siwss_go124.go new file mode 100644 index 000000000..b5bf7803c --- /dev/null +++ b/vendor/github.com/bytedance/sonic/internal/rt/map_siwss_go124.go @@ -0,0 +1,15 @@ +//go:build go1.24 && !go1.25 && goexperiment.swissmap +// +build go1.24,!go1.25,goexperiment.swissmap + +package rt + +import ( + "unsafe" +) + +type GoMapIterator struct { + K unsafe.Pointer + V unsafe.Pointer + T *GoMapType + It unsafe.Pointer +} diff --git a/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go b/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go deleted file mode 100644 index 024912029..000000000 --- a/vendor/github.com/bytedance/sonic/internal/rt/stackmap.go +++ /dev/null @@ -1,181 +0,0 @@ -/** - * Copyright 2023 ByteDance Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package rt - -import ( - `fmt` - `strings` - `unsafe` - -) - -type Bitmap struct { - N int - B []byte -} - -func (self *Bitmap) grow() { - if self.N >= len(self.B) * 8 { - self.B = append(self.B, 0) - } -} - -func (self *Bitmap) mark(i int, bv int) { - if bv != 0 { - self.B[i / 8] |= 1 << (i % 8) - } else { - self.B[i / 8] &^= 1 << (i % 8) - } -} - -func (self *Bitmap) Set(i int, bv int) { - if i >= self.N { - panic("bitmap: invalid bit position") - } else { - self.mark(i, bv) - } -} - -func (self *Bitmap) Append(bv int) { - self.grow() - self.mark(self.N, bv) - self.N++ -} - -func (self *Bitmap) AppendMany(n int, bv int) { - for i := 0; i < n; i++ { - self.Append(bv) - } -} - -// var ( -// _stackMapLock = sync.Mutex{} -// _stackMapCache = make(map[*StackMap]struct{}) -// ) - -type BitVec struct { - N uintptr - B unsafe.Pointer -} - -func (self BitVec) Bit(i uintptr) byte { - return (*(*byte)(unsafe.Pointer(uintptr(self.B) + i / 8)) >> (i % 8)) & 1 -} - -func (self BitVec) String() string { - var i uintptr - var v []string - - /* add each bit */ - for i = 0; i < self.N; i++ { - v = append(v, fmt.Sprintf("%d", self.Bit(i))) - } - - /* join them together */ - return fmt.Sprintf( - "BitVec { %s }", - strings.Join(v, ", "), - ) -} - -type StackMap struct { - N int32 - L int32 - B [1]byte -} - -// func (self *StackMap) add() { -// _stackMapLock.Lock() -// _stackMapCache[self] = struct{}{} -// _stackMapLock.Unlock() -// } - -func (self *StackMap) Pin() uintptr { - // self.add() - return uintptr(unsafe.Pointer(self)) -} - -func (self *StackMap) Get(i int32) BitVec { - return BitVec { - N: uintptr(self.L), - B: unsafe.Pointer(uintptr(unsafe.Pointer(&self.B)) + uintptr(i * ((self.L + 7) >> 3))), - } -} - -func (self *StackMap) String() string { - sb := strings.Builder{} - sb.WriteString("StackMap {") - - /* dump every stack map */ - for i := int32(0); i < self.N; i++ { - sb.WriteRune('\n') - sb.WriteString(" " + self.Get(i).String()) - } - - /* close the stackmap */ - sb.WriteString("\n}") - return sb.String() -} - -func (self *StackMap) MarshalBinary() ([]byte, error) { - size := int(self.N) * int(self.L) + int(unsafe.Sizeof(self.L)) + int(unsafe.Sizeof(self.N)) - return BytesFrom(unsafe.Pointer(self), size, size), nil -} - -var ( - byteType = UnpackEface(byte(0)).Type -) - -const ( - _StackMapSize = unsafe.Sizeof(StackMap{}) -) - -//go:linkname mallocgc runtime.mallocgc -//goland:noinspection GoUnusedParameter -func mallocgc(nb uintptr, vt *GoType, zero bool) unsafe.Pointer - -type StackMapBuilder struct { - b Bitmap -} - -//go:nocheckptr -func (self *StackMapBuilder) Build() (p *StackMap) { - nb := len(self.b.B) - bm := mallocgc(_StackMapSize + uintptr(nb) - 1, byteType, false) - - /* initialize as 1 bitmap of N bits */ - p = (*StackMap)(bm) - p.N, p.L = 1, int32(self.b.N) - copy(BytesFrom(unsafe.Pointer(&p.B), nb, nb), self.b.B) - return -} - -func (self *StackMapBuilder) AddField(ptr bool) { - if ptr { - self.b.Append(1) - } else { - self.b.Append(0) - } -} - -func (self *StackMapBuilder) AddFields(n int, ptr bool) { - if ptr { - self.b.AppendMany(n, 1) - } else { - self.b.AppendMany(n, 0) - } -} diff --git a/vendor/github.com/bytedance/sonic/internal/rt/stubs.go b/vendor/github.com/bytedance/sonic/internal/rt/stubs.go index 1074f491b..f692f1563 100644 --- a/vendor/github.com/bytedance/sonic/internal/rt/stubs.go +++ b/vendor/github.com/bytedance/sonic/internal/rt/stubs.go @@ -24,12 +24,19 @@ import ( //go:noescape //go:linkname Memmove runtime.memmove func Memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr) +//go:noescape +//go:linkname MemEqual runtime.memequal +//goland:noinspection GoUnusedParameter +func MemEqual(a unsafe.Pointer, b unsafe.Pointer, size uintptr) bool //go:linkname Mapiternext runtime.mapiternext func Mapiternext(it *GoMapIterator) //go:linkname Mapiterinit runtime.mapiterinit -func Mapiterinit(t *GoMapType, m *GoMap, it *GoMapIterator) +func Mapiterinit(t *GoMapType, m unsafe.Pointer, it *GoMapIterator) + +//go:linkname Maplen reflect.maplen +func Maplen(h unsafe.Pointer) int //go:linkname IsValidNumber encoding/json.isValidNumber func IsValidNumber(s string) bool @@ -72,6 +79,9 @@ func Mallocgc(size uintptr, typ *GoType, needzero bool) unsafe.Pointer //go:linkname Makemap reflect.makemap func Makemap(*GoType, int) unsafe.Pointer +//go:linkname MakemapSmall runtime.makemap_small +func MakemapSmall() unsafe.Pointer + //go:linkname Mapassign runtime.mapassign //goland:noinspection GoUnusedParameter func Mapassign(t *GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer @@ -128,9 +138,9 @@ func GetMap64Assign(vt reflect.Type) Map64Assign { var emptyBytes = make([]byte, 0, 0) var EmptySlice = *(*GoSlice)(unsafe.Pointer(&emptyBytes)) -//go:linkname makeslice runtime.makeslice +//go:linkname MakeSliceStd runtime.makeslice //goland:noinspection GoUnusedParameter -func makeslice(et *GoType, len int, cap int) unsafe.Pointer +func MakeSliceStd(et *GoType, len int, cap int) unsafe.Pointer func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice { if newLen == 0 { @@ -139,7 +149,7 @@ func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice { if *(*unsafe.Pointer)(oldPtr) == nil { return &GoSlice{ - Ptr: makeslice(et, newLen, newLen), + Ptr: MakeSliceStd(et, newLen, newLen), Len: newLen, Cap: newLen, } @@ -163,3 +173,28 @@ func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice { new.Len = newLen return &new } + +//go:nosplit +//go:linkname Throw runtime.throw +//goland:noinspection GoUnusedParameter +func Throw(s string) + +//go:linkname ConvT64 runtime.convT64 +//goland:noinspection GoUnusedParameter +func ConvT64(v uint64) unsafe.Pointer + +//go:linkname ConvTslice runtime.convTslice +//goland:noinspection GoUnusedParameter +func ConvTslice(v []byte) unsafe.Pointer + +//go:linkname ConvTstring runtime.convTstring +//goland:noinspection GoUnusedParameter +func ConvTstring(v string) unsafe.Pointer + +//go:linkname Mapassign_fast64ptr runtime.mapassign_fast64ptr +//goland:noinspection GoUnusedParameter +func Mapassign_fast64ptr(t *GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer + +//go:noescape +//go:linkname Strhash runtime.strhash +func Strhash(_ unsafe.Pointer, _ uintptr) uintptr |
