1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: add a minor optimisation for array.push_many (#14770)

This commit is contained in:
yuyi 2022-06-17 14:44:13 +08:00 committed by GitHub
parent b89617726c
commit 01fdd5d07f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -636,6 +636,9 @@ fn (mut a array) push(val voidptr) {
// `val` is array.data and user facing usage is `a << [1,2,3]`
[unsafe]
pub fn (mut a3 array) push_many(val voidptr, size int) {
if size <= 0 || isnil(val) {
return
}
a3.ensure_cap(a3.len + size)
if a3.data == val && a3.data != 0 {
// handle `arr << arr`

View File

@ -227,6 +227,9 @@ fn (mut a array) push_noscan(val voidptr) {
// `val` is array.data and user facing usage is `a << [1,2,3]`
[unsafe]
fn (mut a3 array) push_many_noscan(val voidptr, size int) {
if size <= 0 || isnil(val) {
return
}
if a3.data == val && a3.data != 0 {
// handle `arr << arr`
copy := a3.clone()