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:
Ayke van Laethem
2023-03-27 18:55:46 +02:00
committed by Ron Evans
parent 2c0f61cad1
commit 31043628d8
2 changed files with 2 additions and 18 deletions
-16
View File
@@ -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.