mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
transformer: only enable array optimisation with -prod (#12833)
This commit is contained in:
parent
5365984ef5
commit
99f14a7ead
@ -25,7 +25,8 @@ fn access(line string) {
|
||||
}
|
||||
|
||||
fn test_array_optimisation() {
|
||||
mut args := []string{cap: 3}
|
||||
mut args := []string{cap: 4}
|
||||
args << '-prod'
|
||||
args << test
|
||||
args << '-o'
|
||||
args << '-'
|
||||
|
2
vlib/v/tests/testdata/test_array_bound.v
vendored
2
vlib/v/tests/testdata/test_array_bound.v
vendored
@ -93,6 +93,8 @@ fn check_for_c_init_1(a []byte) {
|
||||
for access_it := a[34]; a[34] == 0; {
|
||||
direct(a[34])
|
||||
access(a[35])
|
||||
// work around https://github.com/vlang/v/issues/12832
|
||||
println(access_it)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +156,9 @@ pub fn (mut t Transformer) transform(mut ast_file ast.File) {
|
||||
}
|
||||
|
||||
pub fn (mut t Transformer) find_new_array_len(node ast.AssignStmt) {
|
||||
if !t.pref.is_prod {
|
||||
return
|
||||
}
|
||||
// looking for, array := []type{len:int}
|
||||
mut right := node.right[0]
|
||||
if mut right is ast.ArrayInit {
|
||||
@ -185,6 +188,9 @@ pub fn (mut t Transformer) find_new_array_len(node ast.AssignStmt) {
|
||||
}
|
||||
|
||||
pub fn (mut t Transformer) find_new_range(node ast.AssignStmt) {
|
||||
if !t.pref.is_prod {
|
||||
return
|
||||
}
|
||||
// looking for, array := []type{len:int}
|
||||
mut right := node.right[0]
|
||||
if mut right is ast.IndexExpr {
|
||||
@ -214,10 +220,16 @@ pub fn (mut t Transformer) find_new_range(node ast.AssignStmt) {
|
||||
}
|
||||
|
||||
pub fn (mut t Transformer) find_mut_self_assign(node ast.AssignStmt) {
|
||||
if !t.pref.is_prod {
|
||||
return
|
||||
}
|
||||
// even if mutable we can be sure than `a[1] = a[2] is safe
|
||||
}
|
||||
|
||||
pub fn (mut t Transformer) find_assert_len(node ast.InfixExpr) {
|
||||
if !t.pref.is_prod {
|
||||
return
|
||||
}
|
||||
right := node.right
|
||||
match right {
|
||||
ast.IntegerLiteral {
|
||||
@ -265,6 +277,9 @@ pub fn (mut t Transformer) find_assert_len(node ast.InfixExpr) {
|
||||
}
|
||||
|
||||
pub fn (mut t Transformer) check_safe_array(mut node ast.IndexExpr) {
|
||||
if !t.pref.is_prod {
|
||||
return
|
||||
}
|
||||
if !node.is_array {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user