Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04c5b69

Browse files
committed
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 ofruntime --- the call removed from GetVariable() was the only one thatcould be in a high-usage path ...
1 parent3f9aace commit04c5b69

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

‎src/bin/psql/variables.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.24 2006/06/14 16:49:03 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.25 2006/06/21 16:05:11 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -29,15 +29,13 @@ GetVariable(VariableSpace space, const char *name)
2929
if (!space)
3030
returnNULL;
3131

32-
if (strspn(name,VALID_VARIABLE_CHARS)!=strlen(name))
33-
returnNULL;
34-
35-
for (current=space;current;current=current->next)
32+
for (current=space->next;current;current=current->next)
3633
{
37-
psql_assert(current->name);
38-
psql_assert(current->value);
3934
if (strcmp(current->name,name)==0)
35+
{
36+
psql_assert(current->value);
4037
returncurrent->value;
38+
}
4139
}
4240

4341
returnNULL;
@@ -126,6 +124,9 @@ PrintVariables(VariableSpace space)
126124
{
127125
struct_variable*ptr;
128126

127+
if (!space)
128+
return;
129+
129130
for (ptr=space->next;ptr;ptr=ptr->next)
130131
{
131132
printf("%s = '%s'\n",ptr->name,ptr->value);
@@ -143,18 +144,19 @@ SetVariable(VariableSpace space, const char *name, const char *value)
143144
if (!space)
144145
return false;
145146

146-
if (!value)
147-
returnDeleteVariable(space,name);
148-
149147
if (strspn(name,VALID_VARIABLE_CHARS)!=strlen(name))
150148
return false;
151149

152-
for (current=space,previous=NULL;current;previous=current,current=current->next)
150+
if (!value)
151+
returnDeleteVariable(space,name);
152+
153+
for (previous=space,current=space->next;
154+
current;
155+
previous=current,current=current->next)
153156
{
154-
psql_assert(current->name);
155-
psql_assert(current->value);
156157
if (strcmp(current->name,name)==0)
157158
{
159+
psql_assert(current->value);
158160
free(current->value);
159161
current->value=pg_strdup(value);
160162
return true;
@@ -182,19 +184,16 @@ DeleteVariable(VariableSpace space, const char *name)
182184
if (!space)
183185
return false;
184186

185-
if (strspn(name,VALID_VARIABLE_CHARS)!=strlen(name))
186-
return false;
187-
188-
for (current=space,previous=NULL;current;previous=current,current=current->next)
187+
for (previous=space,current=space->next;
188+
current;
189+
previous=current,current=current->next)
189190
{
190-
psql_assert(current->name);
191-
psql_assert(current->value);
192191
if (strcmp(current->name,name)==0)
193192
{
193+
psql_assert(current->value);
194+
previous->next=current->next;
194195
free(current->name);
195196
free(current->value);
196-
if (previous)
197-
previous->next=current->next;
198197
free(current);
199198
return true;
200199
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp