1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

Reimplement the linked list data structure used throughout the backend.

In the past, we used a 'Lispy' linked list implementation: a "list" was
merely a pointer to the head node of the list. The problem with that
design is that it makes lappend() and length() linear time. This patch
fixes that problem (and others) by maintaining a count of the list
length and a pointer to the tail node along with each head node pointer.
A "list" is now a pointer to a structure containing some meta-data
about the list; the head and tail pointers in that structure refer
to ListCell structures that maintain the actual linked list of nodes.

The function names of the list API have also been changed to, I hope,
be more logically consistent. By default, the old function names are
still available; they will be disabled-by-default once the rest of
the tree has been updated to use the new API names.
This commit is contained in:
Neil Conway
2004-05-26 04:41:50 +00:00
parent 18d0d10563
commit d0b4399d81
125 changed files with 3639 additions and 3038 deletions

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.46 2004/05/14 16:11:25 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.47 2004/05/26 04:41:11 neilc Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@@ -137,7 +137,7 @@ examine_parameter_list(List *parameter, Oid languageOid,
Oid *parameterTypes, const char *parameterNames[])
{
int parameterCount = 0;
List *x;
ListCell *x;
MemSet(parameterTypes, 0, FUNC_MAX_ARGS * sizeof(Oid));
MemSet(parameterNames, 0, FUNC_MAX_ARGS * sizeof(char *));
@@ -202,14 +202,14 @@ examine_parameter_list(List *parameter, Oid languageOid,
*/
static void
compute_attributes_sql_style(const List *options,
compute_attributes_sql_style(List *options,
List **as,
char **language,
char *volatility_p,
bool *strict_p,
bool *security_definer)
{
const List *option;
ListCell *option;
DefElem *as_item = NULL;
DefElem *language_item = NULL;
DefElem *volatility_item = NULL;
@@ -322,7 +322,7 @@ compute_attributes_sql_style(const List *options,
static void
compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatility_p)
{
List *pl;
ListCell *pl;
foreach(pl, parameters)
{
@@ -357,7 +357,7 @@ compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatili
*/
static void
interpret_AS_clause(Oid languageOid, const char *languageName, const List *as,
interpret_AS_clause(Oid languageOid, const char *languageName, List *as,
char **prosrc_str_p, char **probin_str_p)
{
Assert(as != NIL);
@@ -368,8 +368,8 @@ interpret_AS_clause(Oid languageOid, const char *languageName, const List *as,
* For "C" language, store the file name in probin and, when
* given, the link symbol name in prosrc.
*/
*probin_str_p = strVal(lfirst(as));
if (lnext(as) == NULL)
*probin_str_p = strVal(linitial(as));
if (list_length(as) == 1)
*prosrc_str_p = "-";
else
*prosrc_str_p = strVal(lsecond(as));
@@ -377,10 +377,10 @@ interpret_AS_clause(Oid languageOid, const char *languageName, const List *as,
else
{
/* Everything else wants the given string in prosrc. */
*prosrc_str_p = strVal(lfirst(as));
*prosrc_str_p = strVal(linitial(as));
*probin_str_p = "-";
if (lnext(as) != NIL)
if (list_length(as) != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("only one AS item needed for language \"%s\"",