You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
Please see the discussion here. This piece of code:
package main
import (
"fmt""unsafe"
)
// ToLower converts ascii string s to lower-casefuncToLower(sstring) string {
ifs=="" {
return""
}
buf:=make([]byte, len(s))
fmt.Println(unsafe.Pointer(&buf[0])) // just to identify bufferfori:=0; i<len(s); i++ {
c:=s[i]
if'A'<=c&&c<='Z' {
c|=32
}
buf[i] =c
}
returnstring(buf)
}
funcmain() {
s:=ToLower("ASfgQW")
fmt.Println(*(*unsafe.Pointer)(unsafe.Pointer(&s)))
}
shows that both Go and TinyGo compilers fail to detect that buf does not escape, can just be converted to a string and returned. Instead both compilers redundantly allocate a new buffer and copy bytes in return string(buf).
How can this be solved in TinyGo?
The text was updated successfully, but these errors were encountered:
Hi,
Please see the discussion here. This piece of code:
shows that both Go and TinyGo compilers fail to detect that
buf
does not escape, can just be converted to a string and returned. Instead both compilers redundantly allocate a new buffer and copy bytes inreturn string(buf)
.How can this be solved in TinyGo?
The text was updated successfully, but these errors were encountered: