cgen: minor optimization of `index_expr()`

pull/5586/head
yuyi 2020-06-30 20:11:59 +08:00 committed by GitHub
parent a45ad47841
commit 628f13f1c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 105 additions and 110 deletions

View File

@ -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) {
@ -2303,6 +2297,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
}
}
}
}
[inline]
fn (g Gen) expr_is_multi_return_call(expr ast.Expr) bool {