perf: Array.push: move elements directly when source is unique
This commit is contained in:
parent
72cfe18e9f
commit
87e860f871
1 changed files with 10 additions and 4 deletions
|
|
@ -2064,11 +2064,17 @@ extern "C" LEAN_EXPORT obj_res lean_copy_expand_array(obj_arg a, bool expand) {
|
|||
object ** it = lean_array_cptr(a);
|
||||
object ** end = it + sz;
|
||||
object ** dest = lean_array_cptr(r);
|
||||
for (; it != end; ++it, ++dest) {
|
||||
*dest = *it;
|
||||
lean_inc(*it);
|
||||
if (lean_is_exclusive(a)) {
|
||||
// transfer ownership of elements directly instead of inc+dec
|
||||
memcpy(dest, it, sz * sizeof(object *));
|
||||
lean_dealloc(a, lean_array_byte_size(a));
|
||||
} else {
|
||||
for (; it != end; ++it, ++dest) {
|
||||
*dest = *it;
|
||||
lean_inc(*it);
|
||||
}
|
||||
lean_dec(a);
|
||||
}
|
||||
lean_dec(a);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue