diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-05-08 21:21:18 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-05-08 21:21:18 +0000 |
commit | c00b309932b83e7c256a806223078f98d54f6cde (patch) | |
tree | 74fa1a0cbdb8d4bb4515167ffaed4964d8c32d05 /src/backend/nodes/read.c | |
parent | 4af3421161ce7847a019ec0799c898586574801f (diff) |
Alter string format used for integer and OID lists in stored rules.
This simplifies and speeds up the reader by letting it get the representation
right the first time, rather than correcting it after-the-fact. Also,
after int and OID lists become separate node types per Neil's pending
patch, this will let us treat these lists as just plain Nodes instead
of requiring separate read/write macros the way we have now.
Diffstat (limited to 'src/backend/nodes/read.c')
-rw-r--r-- | src/backend/nodes/read.c | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/src/backend/nodes/read.c b/src/backend/nodes/read.c index 402c9991131..e90b413591c 100644 --- a/src/backend/nodes/read.c +++ b/src/backend/nodes/read.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.40 2004/05/06 14:01:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.41 2004/05/08 21:21:18 tgl Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -261,7 +261,8 @@ nodeTokenType(char *token, int length) * lexical tokenizer pg_strtok(). It can read * * Value token nodes (integers, floats, or strings); * * General nodes (via parseNodeString() from readfuncs.c); - * * Lists of the above. + * * Lists of the above; + * * Lists of integers or OIDs. * The return value is declared void *, not Node *, to avoid having to * cast it explicitly in callers that assign to fields of different types. * @@ -300,14 +301,68 @@ nodeRead(char *token, int tok_len) { List *l = NIL; - for (;;) + /*---------- + * Could be an integer list: (i int int ...) + * or an OID list: (o int int ...) + * or a list of nodes/values: (node node ...) + *---------- + */ + token = pg_strtok(&tok_len); + if (token == NULL) + elog(ERROR, "unterminated List structure"); + if (tok_len == 1 && token[0] == 'i') { - token = pg_strtok(&tok_len); - if (token == NULL) - elog(ERROR, "unterminated List structure"); - if (token[0] == ')') - break; - l = lappend(l, nodeRead(token, tok_len)); + /* List of integers */ + for (;;) + { + int val; + char *endptr; + + token = pg_strtok(&tok_len); + if (token == NULL) + elog(ERROR, "unterminated List structure"); + if (token[0] == ')') + break; + val = (int) strtol(token, &endptr, 10); + if (endptr != token + tok_len) + elog(ERROR, "unrecognized integer: \"%.*s\"", + tok_len, token); + l = lappendi(l, val); + } + } + else if (tok_len == 1 && token[0] == 'o') + { + /* List of OIDs */ + for (;;) + { + Oid val; + char *endptr; + + token = pg_strtok(&tok_len); + if (token == NULL) + elog(ERROR, "unterminated List structure"); + if (token[0] == ')') + break; + val = (Oid) strtoul(token, &endptr, 10); + if (endptr != token + tok_len) + elog(ERROR, "unrecognized OID: \"%.*s\"", + tok_len, token); + l = lappendo(l, val); + } + } + else + { + /* List of other node types */ + for (;;) + { + /* We have already scanned next token... */ + if (token[0] == ')') + break; + l = lappend(l, nodeRead(token, tok_len)); + token = pg_strtok(&tok_len); + if (token == NULL) + elog(ERROR, "unterminated List structure"); + } } result = (Node *) l; break; |