mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: use even more efficient array.delete_last()
This commit is contained in:
parent
334497fdc0
commit
c2e9be5a45
@ -261,6 +261,17 @@ pub fn (mut a array) pop() voidptr {
|
||||
return memdup(last_elem, a.element_size)
|
||||
}
|
||||
|
||||
// array.delete_last efficiently deletes the last element of the array
|
||||
pub fn (mut a array) delete_last() {
|
||||
// copy pasting code for performance
|
||||
$if !no_bounds_checking ? {
|
||||
if a.len == 0 {
|
||||
panic('array.pop: array is empty')
|
||||
}
|
||||
}
|
||||
a.len--
|
||||
}
|
||||
|
||||
// array.slice returns an array using the same buffer as original array
|
||||
// but starting from the `start` element and ending with the element before
|
||||
// the `end` element of the original array with the length and capacity
|
||||
|
@ -1047,7 +1047,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
g.writeln('// TypeDecl')
|
||||
}
|
||||
}
|
||||
g.stmt_path_pos.pop()
|
||||
g.stmt_path_pos.delete_last()
|
||||
}
|
||||
|
||||
fn (mut g Gen) write_defer_stmts() {
|
||||
@ -2773,8 +2773,8 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
|
||||
g.match_sumtype_exprs << node.cond
|
||||
g.match_sumtype_syms << type_sym
|
||||
defer {
|
||||
g.match_sumtype_exprs.pop()
|
||||
g.match_sumtype_syms.pop()
|
||||
g.match_sumtype_exprs.delete_last()
|
||||
g.match_sumtype_syms.delete_last()
|
||||
}
|
||||
for j, branch in node.branches {
|
||||
mut sumtype_index := 0
|
||||
@ -4762,7 +4762,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
|
||||
if g.inside_ternary == 0 && !(expr_stmt.expr is ast.IfExpr) {
|
||||
g.writeln(';')
|
||||
}
|
||||
g.stmt_path_pos.pop()
|
||||
g.stmt_path_pos.delete_last()
|
||||
} else {
|
||||
g.stmt(stmt)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user