aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-06-21 16:05:11 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-06-21 16:05:11 +0000
commit04c5b69603c4ec7f80022d0ae6d92ad8a6730141 (patch)
tree86186200560ef3be7af892982b5b0e86a0b313fe /src
parent3f9aace723213b2d2c34cd74144b675faced3a25 (diff)
downloadpostgresql-04c5b69603c4ec7f80022d0ae6d92ad8a6730141.tar.gz
postgresql-04c5b69603c4ec7f80022d0ae6d92ad8a6730141.zip
Clean up psql variable code a little: eliminate unnecessary tests in
GetVariable() and be consistent about treatment of the list header. Motivated by noticing strspn() taking an unreasonable percentage of runtime --- the call removed from GetVariable() was the only one that could be in a high-usage path ...
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/variables.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c
index 26b9f8b925d..e0e416e9e5a 100644
--- a/src/bin/psql/variables.c
+++ b/src/bin/psql/variables.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.24 2006/06/14 16:49:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.25 2006/06/21 16:05:11 tgl Exp $
*/
#include "postgres_fe.h"
#include "common.h"
@@ -29,15 +29,13 @@ GetVariable(VariableSpace space, const char *name)
if (!space)
return NULL;
- if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name))
- return NULL;
-
- for (current = space; current; current = current->next)
+ for (current = space->next; current; current = current->next)
{
- psql_assert(current->name);
- psql_assert(current->value);
if (strcmp(current->name, name) == 0)
+ {
+ psql_assert(current->value);
return current->value;
+ }
}
return NULL;
@@ -126,6 +124,9 @@ PrintVariables(VariableSpace space)
{
struct _variable *ptr;
+ if (!space)
+ return;
+
for (ptr = space->next; ptr; ptr = ptr->next)
{
printf("%s = '%s'\n", ptr->name, ptr->value);
@@ -143,18 +144,19 @@ SetVariable(VariableSpace space, const char *name, const char *value)
if (!space)
return false;
- if (!value)
- return DeleteVariable(space, name);
-
if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name))
return false;
- for (current = space, previous = NULL; current; previous = current, current = current->next)
+ if (!value)
+ return DeleteVariable(space, name);
+
+ for (previous = space, current = space->next;
+ current;
+ previous = current, current = current->next)
{
- psql_assert(current->name);
- psql_assert(current->value);
if (strcmp(current->name, name) == 0)
{
+ psql_assert(current->value);
free(current->value);
current->value = pg_strdup(value);
return true;
@@ -182,19 +184,16 @@ DeleteVariable(VariableSpace space, const char *name)
if (!space)
return false;
- if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name))
- return false;
-
- for (current = space, previous = NULL; current; previous = current, current = current->next)
+ for (previous = space, current = space->next;
+ current;
+ previous = current, current = current->next)
{
- psql_assert(current->name);
- psql_assert(current->value);
if (strcmp(current->name, name) == 0)
{
+ psql_assert(current->value);
+ previous->next = current->next;
free(current->name);
free(current->value);
- if (previous)
- previous->next = current->next;
free(current);
return true;
}