mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: minor optimization of index_expr()
This commit is contained in:
parent
a45ad47841
commit
628f13f1c8
|
@ -2136,12 +2136,9 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
|||
}
|
||||
|
||||
fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||
// TODO else doesn't work with sum types
|
||||
mut is_range := false
|
||||
match node.index {
|
||||
ast.RangeExpr {
|
||||
sym := g.table.get_type_symbol(node.left_type)
|
||||
is_range = true
|
||||
if sym.kind == .string {
|
||||
g.write('string_substr(')
|
||||
g.expr(node.left)
|
||||
|
@ -2176,11 +2173,8 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
|||
g.write('.len')
|
||||
}
|
||||
g.write(')')
|
||||
return
|
||||
}
|
||||
else {}
|
||||
}
|
||||
if !is_range {
|
||||
else {
|
||||
sym := g.table.get_type_symbol(node.left_type)
|
||||
left_is_ptr := node.left_type.is_ptr()
|
||||
if node.left_type.has_flag(.variadic) {
|
||||
|
@ -2302,6 +2296,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
|||
g.write(']')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
|
|
Loading…
Reference in New Issue
Block a user