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.
Этот коммит содержится в:
Ayke van Laethem 2023-03-27 18:55:46 +02:00 коммит произвёл Ron Evans
родитель 2c0f61cad1
коммит 31043628d8
2 изменённых файлов: 2 добавлений и 18 удалений

Просмотреть файл

@ -1209,7 +1209,7 @@ func cvtFloat(v Value, t *rawType) Value {
return makeFloat(v.flags, v.Float(), t) return makeFloat(v.flags, v.Float(), t)
} }
//go:linkname stringToBytes runtime.stringToBytesTyped //go:linkname stringToBytes runtime.stringToBytes
func stringToBytes(x string) []byte func stringToBytes(x string) []byte
func cvtStringBytes(v Value, t *rawType) Value { func cvtStringBytes(v Value, t *rawType) Value {
@ -1221,7 +1221,7 @@ func cvtStringBytes(v Value, t *rawType) Value {
} }
} }
//go:linkname stringFromBytes runtime.stringFromBytesTyped //go:linkname stringFromBytes runtime.stringFromBytes
func stringFromBytes(x []byte) string func stringFromBytes(x []byte) string
func cvtBytesString(v Value, t *rawType) Value { func cvtBytesString(v Value, t *rawType) Value {

Просмотреть файл

@ -77,16 +77,6 @@ func stringFromBytes(x struct {
return _string{ptr: (*byte)(buf), length: x.len} 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. // Convert a string to a []byte slice.
func stringToBytes(x _string) (slice struct { func stringToBytes(x _string) (slice struct {
ptr *byte ptr *byte
@ -101,12 +91,6 @@ func stringToBytes(x _string) (slice struct {
return 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. // Convert a []rune slice to a string.
func stringFromRunes(runeSlice []rune) (s _string) { func stringFromRunes(runeSlice []rune) (s _string) {
// Count the number of characters that will be in the string. // Count the number of characters that will be in the string.