From 2cf5a7047e86ce5cc36ecb2ee9d4739cf4a9aac9 Mon Sep 17 00:00:00 2001 From: Andrey Borodin Date: Fri, 20 Dec 2024 00:19:58 +0500 Subject: [PATCH v6 3/4] prefer non-resizing to constructing empty array --- contrib/intarray/_int_tool.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c index 049c0fda4a..031812ec99 100644 --- a/contrib/intarray/_int_tool.c +++ b/contrib/intarray/_int_tool.c @@ -221,6 +221,9 @@ resize_intArrayType(ArrayType *a, int num) int nbytes; int i; + if (num == ARRNELEMS(a)) + return a; + /* if no elements, return a zero-dimensional array */ if (num <= 0) { @@ -229,9 +232,6 @@ resize_intArrayType(ArrayType *a, int num) return a; } - if (num == ARRNELEMS(a)) - return a; - nbytes = ARR_DATA_OFFSET(a) + sizeof(int) * num; a = (ArrayType *) repalloc(a, nbytes); -- 2.39.5 (Apple Git-154)