From 758329b20cf6d926d99a6d73bc04dceb237eee5b Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Wed, 3 Dec 2025 23:33:18 +0100 Subject: [PATCH v5 5/5] Inline functions that have now become trivial --- src/backend/commands/prepare.c | 17 +++-------------- src/backend/commands/sequence.c | 16 +++------------- src/backend/utils/cache/funccache.c | 22 ++++------------------ 3 files changed, 10 insertions(+), 45 deletions(-) diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 4ad9c10a7f8..ad2f2ab13ec 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -46,7 +46,6 @@ */ static HTAB *prepared_queries = NULL; -static void InitQueryHashTable(void); static ParamListInfo EvaluateParams(ParseState *pstate, PreparedStatement *pstmt, List *params, EState *estate); @@ -364,18 +363,6 @@ EvaluateParams(ParseState *pstate, PreparedStatement *pstmt, List *params, return paramLI; } - -/* - * Initialize query hash table upon first use. - */ -static void -InitQueryHashTable(void) -{ - prepared_queries = hash_make_cxt(PreparedStatement, stmt_name, - "Prepared Queries", 32, - TopMemoryContext); -} - /* * Store all the data pertaining to a query in the hash table using * the specified key. The passed CachedPlanSource should be "unsaved" @@ -393,7 +380,9 @@ StorePreparedStatement(const char *stmt_name, /* Initialize the hash table, if necessary */ if (!prepared_queries) - InitQueryHashTable(); + prepared_queries = hash_make_cxt(PreparedStatement, stmt_name, + "Prepared Queries", 32, + TopMemoryContext); /* Add entry to hash table */ entry = (PreparedStatement *) hash_search(prepared_queries, diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 5a2683c0735..74f5aa49d54 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -89,7 +89,6 @@ static SeqTableData *last_used_seq = NULL; static void fill_seq_with_data(Relation rel, HeapTuple tuple); static void fill_seq_fork_with_data(Relation rel, HeapTuple tuple, ForkNumber forkNum); static Relation lock_and_open_sequence(SeqTable seq); -static void create_seq_hashtable(void); static void init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel); static Form_pg_sequence_data read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple); @@ -1107,17 +1106,6 @@ lock_and_open_sequence(SeqTable seq) return sequence_open(seq->relid, NoLock); } -/* - * Creates the hash table for storing sequence data - */ -static void -create_seq_hashtable(void) -{ - seqhashtab = hash_make_cxt(SeqTableData, relid, - "Sequence values", 16, - TopMemoryContext); -} - /* * Given a relation OID, open and lock the sequence. p_elm and p_rel are * output parameters. @@ -1131,7 +1119,9 @@ init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel) /* Find or create a hash table entry for this sequence */ if (seqhashtab == NULL) - create_seq_hashtable(); + seqhashtab = hash_make_cxt(SeqTableData, relid, + "Sequence values", 16, + TopMemoryContext); elm = (SeqTable) hash_search(seqhashtab, &relid, HASH_ENTER, &found); diff --git a/src/backend/utils/cache/funccache.c b/src/backend/utils/cache/funccache.c index bef938c37c0..0e5bfa2a56a 100644 --- a/src/backend/utils/cache/funccache.c +++ b/src/backend/utils/cache/funccache.c @@ -50,23 +50,6 @@ static uint32 cfunc_hash(const void *key, Size keysize); static int cfunc_match(const void *key1, const void *key2, Size keysize); -/* - * Initialize the hash table on first use. - * - * The hash table will be in TopMemoryContext regardless of caller's context. - */ -static void -cfunc_hashtable_init(void) -{ - /* don't allow double-initialization */ - Assert(cfunc_hashtable == NULL); - - cfunc_hashtable = hash_make_fn_cxt(CachedFunctionHashEntry, key, - "Cached function hash", FUNCS_PER_USER, - cfunc_hash, cfunc_match, - TopMemoryContext); -} - /* * cfunc_hash: hash function for cfunc hash table * @@ -165,7 +148,10 @@ cfunc_hashtable_insert(CachedFunction *function, bool found; if (cfunc_hashtable == NULL) - cfunc_hashtable_init(); + cfunc_hashtable = hash_make_fn_cxt(CachedFunctionHashEntry, key, + "Cached function hash", FUNCS_PER_USER, + cfunc_hash, cfunc_match, + TopMemoryContext); hentry = (CachedFunctionHashEntry *) hash_search(cfunc_hashtable, func_key, -- 2.52.0