mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: don't memdup element for array.pop
(depends on how cgen works) (#13789)
The voidptr returned is immediately dereferenced in cgen so the memory is copied before the array can be appended to: `*(int*)array_pop(&a)`
This commit is contained in:
parent
f66d2f5d43
commit
afbccf79f7
@ -402,12 +402,13 @@ pub fn (mut a array) pop() voidptr {
|
||||
a.len = new_len
|
||||
// Note: a.cap is not changed here *on purpose*, so that
|
||||
// further << ops on that array will be more efficient.
|
||||
return unsafe { memdup(last_elem, a.element_size) }
|
||||
return last_elem
|
||||
}
|
||||
|
||||
// delete_last efficiently deletes the last element of the array.
|
||||
// It does it simply by reducing the length of the array by 1.
|
||||
// If the array is empty, this will panic.
|
||||
// See also: [trim](#array.trim)
|
||||
pub fn (mut a array) delete_last() {
|
||||
// copy pasting code for performance
|
||||
$if !no_bounds_checking ? {
|
||||
|
Loading…
Reference in New Issue
Block a user