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

master
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]` // `val` is array.data and user facing usage is `a << [1,2,3]`
[unsafe] [unsafe]
pub fn (mut a3 array) push_many(val voidptr, size int) { pub fn (mut a3 array) push_many(val voidptr, size int) {
if size <= 0 || isnil(val) {
return
}
a3.ensure_cap(a3.len + size) a3.ensure_cap(a3.len + size)
if a3.data == val && a3.data != 0 { if a3.data == val && a3.data != 0 {
// handle `arr << arr` // 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]` // `val` is array.data and user facing usage is `a << [1,2,3]`
[unsafe] [unsafe]
fn (mut a3 array) push_many_noscan(val voidptr, size int) { fn (mut a3 array) push_many_noscan(val voidptr, size int) {
if size <= 0 || isnil(val) {
return
}
if a3.data == val && a3.data != 0 { if a3.data == val && a3.data != 0 {
// handle `arr << arr` // handle `arr << arr`
copy := a3.clone() copy := a3.clone()