Skip to content

Commit

Permalink
fix: remove some linknames
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Jul 8, 2024
1 parent 765ecdb commit 458b078
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 151 deletions.
105 changes: 99 additions & 6 deletions ast/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,106 @@ func mem2ptr(s []byte) unsafe.Pointer {
return (*rt.GoSlice)(unsafe.Pointer(&s)).Ptr
}

var (
//go:linkname safeSet encoding/json.safeSet
safeSet [utf8.RuneSelf]bool
var safeSet = [utf8.RuneSelf]bool{
' ': true,
'!': true,
'"': false,
'#': true,
'$': true,
'%': true,
'&': true,
'\'': true,
'(': true,
')': true,
'*': true,
'+': true,
',': true,
'-': true,
'.': true,
'/': true,
'0': true,
'1': true,
'2': true,
'3': true,
'4': true,
'5': true,
'6': true,
'7': true,
'8': true,
'9': true,
':': true,
';': true,
'<': true,
'=': true,
'>': true,
'?': true,
'@': true,
'A': true,
'B': true,
'C': true,
'D': true,
'E': true,
'F': true,
'G': true,
'H': true,
'I': true,
'J': true,
'K': true,
'L': true,
'M': true,
'N': true,
'O': true,
'P': true,
'Q': true,
'R': true,
'S': true,
'T': true,
'U': true,
'V': true,
'W': true,
'X': true,
'Y': true,
'Z': true,
'[': true,
'\\': false,
']': true,
'^': true,
'_': true,
'`': true,
'a': true,
'b': true,
'c': true,
'd': true,
'e': true,
'f': true,
'g': true,
'h': true,
'i': true,
'j': true,
'k': true,
'l': true,
'm': true,
'n': true,
'o': true,
'p': true,
'q': true,
'r': true,
's': true,
't': true,
'u': true,
'v': true,
'w': true,
'x': true,
'y': true,
'z': true,
'{': true,
'|': true,
'}': true,
'~': true,
'\u007f': true,
}

//go:linkname hex encoding/json.hex
hex string
)
var hex = "0123456789abcdef"

//go:linkname unquoteBytes encoding/json.unquoteBytes
func unquoteBytes(s []byte) (t []byte, ok bool)
21 changes: 4 additions & 17 deletions internal/decoder/optdec/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,11 +967,7 @@ func AsEfaceFast(iter *NodeIter, ctx *Context) interface{} {
val = sp
goto _arr_val;
} else {
ctx.efacePool.ConvTSlice(rt.GoSlice{
Ptr: rt.ZSTPtr,
Len: 0,
Cap: 0,
}, rt.SliceEfaceType, unsafe.Pointer(&root))
ctx.efacePool.ConvTSlice(rt.EmptySlice, rt.SliceEfaceType, unsafe.Pointer(&root))
}
case KStringCommon: ctx.efacePool.ConvTstring(node.StringRef(ctx), unsafe.Pointer(&root))
case KStringEscaped: ctx.efacePool.ConvTstring(node.StringCopyEsc(ctx), unsafe.Pointer(&root))
Expand All @@ -993,9 +989,8 @@ _object_key:
} else {
key = node.StringCopyEsc(ctx)
}
// interface{} slot in map bucket

//println("key is **", key, "** mp is ", mp)
// interface{} slot in map bucket
val = rt.Mapassign_faststr(rt.MapEfaceMapType, mp, key)
vt = &(*rt.GoEface)(val).Type
vp = &(*rt.GoEface)(val).Value
Expand All @@ -1021,11 +1016,7 @@ _object_key:
case KArray:
newSize := node.Array().Len()
if newSize == 0 {
ctx.efacePool.ConvTSlice(rt.GoSlice{
Ptr: rt.ZSTPtr,
Len: 0,
Cap: 0,
}, rt.SliceEfaceType, val)
ctx.efacePool.ConvTSlice(rt.EmptySlice, rt.SliceEfaceType, val)
break;
}

Expand Down Expand Up @@ -1124,11 +1115,7 @@ _arr_val:
case KArray:
newSize := node.Array().Len()
if newSize == 0 {
ctx.efacePool.ConvTSlice(rt.GoSlice{
Ptr: rt.ZSTPtr,
Len: newSize,
Cap: newSize,
}, rt.SliceEfaceType, val)
ctx.efacePool.ConvTSlice(rt.EmptySlice, rt.SliceEfaceType, val)
break;
}

Expand Down
58 changes: 0 additions & 58 deletions internal/decoder/optdec/options.go

This file was deleted.

8 changes: 1 addition & 7 deletions internal/rt/rt_stubs_go116.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@ import (
"unsafe"
)

//go:linkname roundupsize runtime.roundupsize
func roundupsize(size uintptr) uintptr

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
return &EmptySlice
}

if *(*unsafe.Pointer)(oldPtr) == nil {
Expand Down
13 changes: 3 additions & 10 deletions internal/rt/rt_stubs_go120.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
//go:build go1.20 && !go1.22
// +build go1.20,!go1.22
//go:build go1.20 && !go1.23
// +build go1.20,!go1.23

package rt

import (
"unsafe"
)

//go:linkname roundupsize runtime.roundupsize
func roundupsize(size uintptr) uintptr

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
return &EmptySlice
}

if *(*unsafe.Pointer)(oldPtr) == nil {
Expand Down
48 changes: 0 additions & 48 deletions internal/rt/rt_stubs_go123.go

This file was deleted.

3 changes: 3 additions & 0 deletions internal/rt/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ func GetMap64Assign(vt reflect.Type) Map64Assign {
}
}


var emptyBytes = make([]byte, 0, 0)
var EmptySlice = *(*GoSlice)(unsafe.Pointer(&emptyBytes))

Check failure on line 129 in internal/rt/stubs.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected var after top level declaration

Check failure on line 129 in internal/rt/stubs.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected var after top level declaration

Check failure on line 129 in internal/rt/stubs.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected var after top level declaration
5 changes: 0 additions & 5 deletions internal/rt/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ func AsGoType(t uintptr) *GoType {
return (*GoType)(unsafe.Pointer(t))
}

//go:linkname zerobase runtime.zerobase
var zerobase uintptr

var (
BoolType = UnpackType(reflect.TypeOf(false))
ByteType = UnpackType(reflect.TypeOf(byte(0)))
Expand Down Expand Up @@ -45,6 +42,4 @@ var (
MapStringType = UnpackType(reflect.TypeOf(map[string]string(nil)))

MapEfaceMapType = MapType(UnpackType(reflect.TypeOf(map[string]interface{}(nil))))

ZSTPtr = unsafe.Pointer(&zerobase)
)

0 comments on commit 458b078

Please sign in to comment.