mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
reflect: use direct calls to runtime string functions
The runtime.stringFromBytesTyped and runtime.stringToBytesTyped functions aren't really necessary, because they have the same LLVM IR signature. Therefore, remove them and link directly to the functions that the compiler uses internally.
This commit is contained in:
committed by
Ron Evans
parent
2c0f61cad1
commit
31043628d8
@@ -77,16 +77,6 @@ func stringFromBytes(x struct {
|
||||
return _string{ptr: (*byte)(buf), length: x.len}
|
||||
}
|
||||
|
||||
func stringFromBytesTyped(x []byte) string {
|
||||
slice := *(*struct {
|
||||
ptr *byte
|
||||
len uintptr
|
||||
cap uintptr
|
||||
})(unsafe.Pointer(&x))
|
||||
s := stringFromBytes(slice)
|
||||
return *(*string)(unsafe.Pointer(&s))
|
||||
}
|
||||
|
||||
// Convert a string to a []byte slice.
|
||||
func stringToBytes(x _string) (slice struct {
|
||||
ptr *byte
|
||||
@@ -101,12 +91,6 @@ func stringToBytes(x _string) (slice struct {
|
||||
return
|
||||
}
|
||||
|
||||
func stringToBytesTyped(x string) []byte {
|
||||
s := *(*_string)(unsafe.Pointer(&x))
|
||||
slice := stringToBytes(s)
|
||||
return *(*[]byte)(unsafe.Pointer(&slice))
|
||||
}
|
||||
|
||||
// Convert a []rune slice to a string.
|
||||
func stringFromRunes(runeSlice []rune) (s _string) {
|
||||
// Count the number of characters that will be in the string.
|
||||
|
||||
Reference in New Issue
Block a user