summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2006-06-21 16:05:11 +0000
committerTom Lane2006-06-21 16:05:11 +0000
commit42141afd10b2f4c3ea08a2ec7648de503fe4323c (patch)
tree4b2442b2221e5acbf2ee2d5d021b4e0e364cc1cc
parent1c0d4717c9cf64fac14702437c131e77abd0b87c (diff)
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 ...
-rw-r--r--src/bin/psql/variables.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c
index 1a54a95190..c2bfa8137e 100644
--- a/src/bin/psql/variables.c
+++ b/src/bin/psql/variables.c
@@ -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;
}