From 56cf0b0a2e0af89be9701983142308ac726e0d9a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 7 May 2022 10:35:56 +0300 Subject: [PATCH] builtin: inline manually isnil calls in array.push_many (very frequently called) --- vlib/builtin/array.v | 11 +++++------ vlib/builtin/array_d_gcboehm_opt.v | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 65b27022fc..8174266947 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -601,7 +601,7 @@ pub fn (a &array) clone_to_depth(depth int) array { } return arr } else { - if !isnil(a.data) { + if a.data != 0 { unsafe { vmemcpy(&u8(arr.data), a.data, u64(a.cap) * u64(a.element_size)) } } return arr @@ -637,16 +637,15 @@ fn (mut a array) push(val voidptr) { [unsafe] pub fn (mut a3 array) push_many(val voidptr, size int) { a3.ensure_cap(a3.len + size) - if a3.data == val && !isnil(a3.data) { + if a3.data == val && a3.data != 0 { // handle `arr << arr` copy := a3.clone() unsafe { - // vmemcpy(a.data, copy.data, copy.element_size * copy.len) - vmemcpy(a3.get_unsafe(a3.len), copy.data, u64(a3.element_size) * u64(size)) + vmemcpy(&u8(a3.data) + u64(a3.element_size) * u64(a3.len), copy.data, u64(a3.element_size) * u64(size)) } } else { - if !isnil(a3.data) && !isnil(val) { - unsafe { vmemcpy(a3.get_unsafe(a3.len), val, u64(a3.element_size) * u64(size)) } + if a3.data != 0 && val != 0 { + unsafe { vmemcpy(&u8(a3.data) + u64(a3.element_size) * u64(a3.len), val, u64(a3.element_size) * u64(size)) } } } a3.len += size diff --git a/vlib/builtin/array_d_gcboehm_opt.v b/vlib/builtin/array_d_gcboehm_opt.v index f68ab7665a..b90c008788 100644 --- a/vlib/builtin/array_d_gcboehm_opt.v +++ b/vlib/builtin/array_d_gcboehm_opt.v @@ -210,7 +210,7 @@ fn (a &array) clone_to_depth_noscan(depth int) array { } return arr } else { - if !isnil(a.data) { + if a.data != 0 { unsafe { vmemcpy(&u8(arr.data), a.data, u64(a.cap) * u64(a.element_size)) } } 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]` [unsafe] 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` copy := a3.clone() a3.ensure_cap_noscan(a3.len + size) @@ -236,7 +236,7 @@ fn (mut a3 array) push_many_noscan(val voidptr, size int) { } } else { 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)) } } }