Skip to content

Commit

Permalink
fix: remove some linknames (#667)
Browse files Browse the repository at this point in the history
Co-authored-by: duanyi.aster <[email protected]>
  • Loading branch information
liuq19 and AsterDY authored Jul 8, 2024
1 parent 6452c4b commit 121df0a
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 276 deletions.
31 changes: 0 additions & 31 deletions ast/b64_amd64.go

This file was deleted.

31 changes: 0 additions & 31 deletions ast/b64_compat.go

This file was deleted.

14 changes: 8 additions & 6 deletions ast/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package ast

import (
`sync`
`unicode/utf8`
"sync"
"unicode/utf8"

"github.com/bytedance/sonic/internal/rt"
)

const (
Expand All @@ -30,7 +32,7 @@ func quoteString(e *[]byte, s string) {
start := 0
for i := 0; i < len(s); {
if b := s[i]; b < utf8.RuneSelf {
if safeSet[b] {
if rt.SafeSet[b] {
i++
continue
}
Expand All @@ -54,8 +56,8 @@ func quoteString(e *[]byte, s string) {
// user-controlled strings are rendered into JSON
// and served to some browsers.
*e = append(*e, `u00`...)
*e = append(*e, hex[b>>4])
*e = append(*e, hex[b&0xF])
*e = append(*e, rt.Hex[b>>4])
*e = append(*e, rt.Hex[b&0xF])
}
i++
start = i
Expand All @@ -76,7 +78,7 @@ func quoteString(e *[]byte, s string) {
*e = append(*e, s[start:i]...)
}
*e = append(*e, `\u202`...)
*e = append(*e, hex[c&0xF])
*e = append(*e, rt.Hex[c&0xF])
i += size
start = i
continue
Expand Down
2 changes: 1 addition & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ func NewBytes(src []byte) Node {
if len(src) == 0 {
panic("empty src bytes")
}
out := encodeBase64(src)
out := rt.EncodeBase64(src)
return NewString(out)
}

Expand Down
9 changes: 0 additions & 9 deletions ast/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ast

import (
`unsafe`
`unicode/utf8`

`github.com/bytedance/sonic/internal/rt`
)
Expand All @@ -37,13 +36,5 @@ func mem2ptr(s []byte) unsafe.Pointer {
return (*rt.GoSlice)(unsafe.Pointer(&s)).Ptr
}

var (
//go:linkname safeSet encoding/json.safeSet
safeSet [utf8.RuneSelf]bool

//go:linkname hex encoding/json.hex
hex string
)

//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.

16 changes: 4 additions & 12 deletions internal/encoder/alg/spec_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Quote(e []byte, s string, double bool) []byte {

for i := 0; i < len(s); {
if b := s[i]; b < utf8.RuneSelf {
if safeSet[b] {
if rt.SafeSet[b] {
i++
continue
}
Expand All @@ -79,8 +79,8 @@ func Quote(e []byte, s string, double bool) []byte {
// user-controlled strings are rendered into JSON
// and served to some browsers.
e = append(e, `u00`...)
e = append(e, hex[b>>4])
e = append(e, hex[b&0xF])
e = append(e, rt.Hex[b>>4])
e = append(e, rt.Hex[b&0xF])
}
i++
start = i
Expand All @@ -101,7 +101,7 @@ func Quote(e []byte, s string, double bool) []byte {
e = append(e, s[start:i]...)
}
e = append(e, `\u202`...)
e = append(e, hex[c&0xF])
e = append(e, rt.Hex[c&0xF])
i += size
start = i
continue
Expand All @@ -121,14 +121,6 @@ func Quote(e []byte, s string, double bool) []byte {
}
}

var (
//go:linkname safeSet encoding/json.safeSet
safeSet [utf8.RuneSelf]bool

//go:linkname hex encoding/json.hex
hex string
)

func HtmlEscape(dst []byte, src []byte) []byte {
buf := bytes.NewBuffer(dst)
json.HTMLEscape(buf, src)
Expand Down
40 changes: 0 additions & 40 deletions internal/rt/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,3 @@ _entry:
_stack_grow:
CALL runtime·morestack_noctxt<>(SB)
JMP _entry


TEXT ·StopProf(SB), NOSPLIT, $0-0
NO_LOCAL_POINTERS
CMPB github·com∕bytedance∕sonic∕internal∕rt·StopProfiling(SB), $0
JEQ _ret_1
MOVL $1, AX
LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX
LOCK
XADDL AX, (CX)
MOVL runtime·prof+4(SB), AX
TESTL AX, AX
JEQ _ret_1
MOVL AX, github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB)
MOVL $0, runtime·prof+4(SB)
_ret_1:
RET


TEXT ·StartProf(SB), NOSPLIT, $0-0
NO_LOCAL_POINTERS
CMPB github·com∕bytedance∕sonic∕internal∕rt·StopProfiling(SB), $0
JEQ _ret_2
MOVL $-1, AX
LEAQ github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), CX
LOCK
XADDL AX, (CX)
CMPL github·com∕bytedance∕sonic∕internal∕rt·yieldCount(SB), $0
JNE _ret_2
CMPL runtime·prof+4(SB), $0
JNE _ret_2
CMPL github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB), $0
JNE _branch_1
MOVL $100, github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB)
_branch_1:
MOVL github·com∕bytedance∕sonic∕internal∕rt·oldHz(SB), AX
MOVL AX, runtime·prof+4(SB)
_ret_2:
RET

4 changes: 4 additions & 0 deletions internal/rt/base64_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func DecodeBase64(raw []byte) ([]byte, error) {
}
return ret[:n], nil
}

func EncodeBase64(src []byte) string {
return base64x.StdEncoding.EncodeToString(src)
}
4 changes: 4 additions & 0 deletions internal/rt/base64_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ func DecodeBase64(raw []byte) ([]byte, error) {
}
return ret[:n], nil
}

func EncodeBase64(src []byte) string {
return base64.StdEncoding.EncodeToString(src)
}
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
Loading

0 comments on commit 121df0a

Please sign in to comment.