mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
transform: optimize string comparisons against ""
This optimizes a common pattern like:
if s != "" {
...
}
to:
if len(s) != 0 {
...
}
This avoids a runtime call and thus produces slightly better code.
This commit is contained in:
committed by
Ron Evans
parent
13db2c13e5
commit
f9865a08bc
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user