From 9030adbf9e46f66812fb11849c367bbcf5b3a427 Mon Sep 17 00:00:00 2001 From: pgaddict Date: Wed, 28 Jun 2023 14:09:58 +0800 Subject: [PATCH] make int4hashset_contains strict and header file changes. --- hashset--0.0.1.sql | 2 +- hashset-api.c | 20 ++++---------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/hashset--0.0.1.sql b/hashset--0.0.1.sql index d0478ce9..d448ee69 100644 --- a/hashset--0.0.1.sql +++ b/hashset--0.0.1.sql @@ -55,7 +55,7 @@ LANGUAGE C IMMUTABLE; CREATE OR REPLACE FUNCTION hashset_contains(int4hashset, int) RETURNS boolean AS 'hashset', 'int4hashset_contains' -LANGUAGE C IMMUTABLE; +LANGUAGE C IMMUTABLE STRICT; CREATE OR REPLACE FUNCTION hashset_union(int4hashset, int4hashset) RETURNS int4hashset diff --git a/hashset-api.c b/hashset-api.c index a4beef4e..ff948b55 100644 --- a/hashset-api.c +++ b/hashset-api.c @@ -1,8 +1,6 @@ #include "hashset.h" -#include #include -#include #include #include #include @@ -377,17 +375,11 @@ int4hashset_contains(PG_FUNCTION_ARGS) int32 value; bool result; - if (PG_ARGISNULL(0)) - PG_RETURN_NULL(); - set = PG_GETARG_INT4HASHSET(0); if (set->nelements == 0 && !set->null_element) PG_RETURN_BOOL(false); - if (PG_ARGISNULL(1)) - PG_RETURN_NULL(); - value = PG_GETARG_INT32(1); result = int4hashset_contains_element(set, value); @@ -696,10 +688,8 @@ int4hashset_to_array(PG_FUNCTION_ARGS) set = PG_GETARG_INT4HASHSET(0); /* if hashset is empty and does not contain null, return an empty array */ - if(set->nelements == 0 && !set->null_element) { - Datum d = PointerGetDatum(construct_empty_array(INT4OID)); - PG_RETURN_ARRAYTYPE_P(d); - } + if(set->nelements == 0 && !set->null_element) + PG_RETURN_ARRAYTYPE_P(construct_empty_array(INT4OID)); sbitmap = set->data; svalues = (int32 *) (set->data + CEIL_DIV(set->capacity, 8)); @@ -733,10 +723,8 @@ int4hashset_to_sorted_array(PG_FUNCTION_ARGS) set = PG_GETARG_INT4HASHSET(0); /* if hashset is empty and does not contain null, return an empty array */ - if(set->nelements == 0 && !set->null_element) { - Datum d = PointerGetDatum(construct_empty_array(INT4OID)); - PG_RETURN_ARRAYTYPE_P(d); - } + if(set->nelements == 0 && !set->null_element) + PG_RETURN_ARRAYTYPE_P(construct_empty_array(INT4OID)); /* extract the sorted elements from the hashset */ values = int4hashset_extract_sorted_elements(set); -- 2.34.1