builtin: inline manually isnil calls in array.push_many (very frequently called)

master
Delyan Angelov 2022-05-07 10:35:56 +03:00
parent 7f974a275a
commit 56cf0b0a2e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 8 additions and 9 deletions

View File

@ -601,7 +601,7 @@ pub fn (a &array) clone_to_depth(depth int) array {
} }
return arr return arr
} else { } else {
if !isnil(a.data) { if a.data != 0 {
unsafe { vmemcpy(&u8(arr.data), a.data, u64(a.cap) * u64(a.element_size)) } unsafe { vmemcpy(&u8(arr.data), a.data, u64(a.cap) * u64(a.element_size)) }
} }
return arr return arr
@ -637,16 +637,15 @@ fn (mut a array) push(val voidptr) {
[unsafe] [unsafe]
pub fn (mut a3 array) push_many(val voidptr, size int) { pub fn (mut a3 array) push_many(val voidptr, size int) {
a3.ensure_cap(a3.len + size) a3.ensure_cap(a3.len + size)
if a3.data == val && !isnil(a3.data) { if a3.data == val && a3.data != 0 {
// handle `arr << arr` // handle `arr << arr`
copy := a3.clone() copy := a3.clone()
unsafe { unsafe {
// vmemcpy(a.data, copy.data, copy.element_size * copy.len) vmemcpy(&u8(a3.data) + u64(a3.element_size) * u64(a3.len), copy.data, u64(a3.element_size) * u64(size))
vmemcpy(a3.get_unsafe(a3.len), copy.data, u64(a3.element_size) * u64(size))
} }
} else { } else {
if !isnil(a3.data) && !isnil(val) { if a3.data != 0 && val != 0 {
unsafe { vmemcpy(a3.get_unsafe(a3.len), val, u64(a3.element_size) * u64(size)) } unsafe { vmemcpy(&u8(a3.data) + u64(a3.element_size) * u64(a3.len), val, u64(a3.element_size) * u64(size)) }
} }
} }
a3.len += size a3.len += size

View File

@ -210,7 +210,7 @@ fn (a &array) clone_to_depth_noscan(depth int) array {
} }
return arr return arr
} else { } else {
if !isnil(a.data) { if a.data != 0 {
unsafe { vmemcpy(&u8(arr.data), a.data, u64(a.cap) * u64(a.element_size)) } unsafe { vmemcpy(&u8(arr.data), a.data, u64(a.cap) * u64(a.element_size)) }
} }
return arr return arr
@ -227,7 +227,7 @@ 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 a3.data == val && !isnil(a3.data) { if a3.data == val && a3.data != 0 {
// handle `arr << arr` // handle `arr << arr`
copy := a3.clone() copy := a3.clone()
a3.ensure_cap_noscan(a3.len + size) a3.ensure_cap_noscan(a3.len + size)
@ -236,7 +236,7 @@ fn (mut a3 array) push_many_noscan(val voidptr, size int) {
} }
} else { } else {
a3.ensure_cap_noscan(a3.len + size) a3.ensure_cap_noscan(a3.len + size)
if !isnil(a3.data) && !isnil(val) { if a3.data != 0 && val != 0 {
unsafe { vmemcpy(a3.get_unsafe(a3.len), val, u64(a3.element_size) * u64(size)) } unsafe { vmemcpy(a3.get_unsafe(a3.len), val, u64(a3.element_size) * u64(size)) }
} }
} }