From 01fdd5d07fad362d77f7a86761eb35334b47e4d8 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 17 Jun 2022 14:44:13 +0800 Subject: [PATCH] cgen: add a minor optimisation for array.push_many (#14770) --- vlib/builtin/array.v | 3 +++ vlib/builtin/array_d_gcboehm_opt.v | 3 +++ 2 files changed, 6 insertions(+) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 454d062319..faecdf56b1 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -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` diff --git a/vlib/builtin/array_d_gcboehm_opt.v b/vlib/builtin/array_d_gcboehm_opt.v index b90c008788..b94231943f 100644 --- a/vlib/builtin/array_d_gcboehm_opt.v +++ b/vlib/builtin/array_d_gcboehm_opt.v @@ -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()