mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 19:23:25 +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
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user