aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-03-27 18:55:46 +0200
committerRon Evans <[email protected]>2023-03-27 22:24:20 +0200
commit31043628d8349d52e81d3fc4deaf556c299299ae (patch)
tree2bed8ddd22ae5d38a6923921a8bb392dd8ba2f41
parent2c0f61cad10f32f40fe34561ec4539b465f43bf3 (diff)
downloadtinygo-31043628d8349d52e81d3fc4deaf556c299299ae.tar.gz
tinygo-31043628d8349d52e81d3fc4deaf556c299299ae.zip
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.
-rw-r--r--src/reflect/value.go4
-rw-r--r--src/runtime/string.go16
2 files changed, 2 insertions, 18 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go
index 487e0d82b..ed4d01cdf 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -1209,7 +1209,7 @@ func cvtFloat(v Value, t *rawType) Value {
return makeFloat(v.flags, v.Float(), t)
}
-//go:linkname stringToBytes runtime.stringToBytesTyped
+//go:linkname stringToBytes runtime.stringToBytes
func stringToBytes(x string) []byte
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 cvtBytesString(v Value, t *rawType) Value {
diff --git a/src/runtime/string.go b/src/runtime/string.go
index b08b96f4a..13bfcd0ed 100644
--- a/src/runtime/string.go
+++ b/src/runtime/string.go
@@ -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.