mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
f9865a08bc
This optimizes a common pattern like:
if s != "" {
...
}
to:
if len(s) != 0 {
...
}
This avoids a runtime call and thus produces slightly better code.
24 lines
446 B
Go
24 lines
446 B
Go
package transform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"tinygo.org/x/go-llvm"
|
|
)
|
|
|
|
func TestOptimizeStringToBytes(t *testing.T) {
|
|
t.Parallel()
|
|
testTransform(t, "testdata/stringtobytes", func(mod llvm.Module) {
|
|
// Run optimization pass.
|
|
OptimizeStringToBytes(mod)
|
|
})
|
|
}
|
|
|
|
func TestOptimizeStringEqual(t *testing.T) {
|
|
t.Parallel()
|
|
testTransform(t, "testdata/stringequal", func(mod llvm.Module) {
|
|
// Run optimization pass.
|
|
OptimizeStringEqual(mod)
|
|
})
|
|
}
|