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)`pull/13800/head
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