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

Commit9396802

Browse files
committed
more cleanups...of note, appendStringInfo now performs like sprintf(),where you state a format and arguments. the old behavior requiredeach appendStringInfo to have to have a sprintf() before it if anyformatting was required.Also shortened several instances where there were multiple appendStringInfo()calls in a row, doing nothing more then adding one more word to the String,instead of doing them all in one call.
1 parentdf1468e commit9396802

File tree

12 files changed

+130
-134
lines changed

12 files changed

+130
-134
lines changed

‎src/backend/commands/explain.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
/*-------------------------------------------------------------------------
2-
*
1+
/*
32
* explain.c--
43
* Explain the query execution plan
54
*
65
* Copyright (c) 1994-5, Regents of the University of California
76
*
7+
* $Id: explain.c,v 1.29 1998/12/14 08:11:00 scrappy Exp $
88
*
9-
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.28 1998/12/14 05:18:43 scrappy Exp $
11-
*
12-
*-------------------------------------------------------------------------
139
*/
1410
#include<stdio.h>
1511
#include<string.h>
@@ -217,7 +213,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
217213
{
218214
relation=RelationIdCacheGetRelation((int)lfirst(l));
219215
if (++i>1)
216+
{
220217
appendStringInfo(str,", ");
218+
}
221219
appendStringInfo(str, (RelationGetRelationName(relation))->data);
222220
}
223221
caseT_SeqScan:
@@ -239,9 +237,8 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
239237
}
240238
if (es->printCost)
241239
{
242-
snprintf(buf,1000," (cost=%.2f size=%d width=%d)",
240+
appendStringInfo(str," (cost=%.2f size=%d width=%d)",
243241
plan->cost,plan->plan_size,plan->plan_width);
244-
appendStringInfo(str,buf);
245242
}
246243
appendStringInfo(str,"\n");
247244

@@ -251,14 +248,18 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
251248
List*saved_rtable=es->rtable;
252249
List*lst;
253250

254-
for (i=0;i<indent;i++)
251+
for (i=0;i<indent;i++)
252+
{
255253
appendStringInfo(str," ");
254+
}
256255
appendStringInfo(str," InitPlan\n");
257256
foreach(lst,plan->initPlan)
258257
{
259258
es->rtable= ((SubPlan*)lfirst(lst))->rtable;
260259
for (i=0;i<indent;i++)
260+
{
261261
appendStringInfo(str," ");
262+
}
262263
appendStringInfo(str," -> ");
263264
explain_outNode(str, ((SubPlan*)lfirst(lst))->plan,indent+2,es);
264265
}
@@ -269,7 +270,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
269270
if (outerPlan(plan))
270271
{
271272
for (i=0;i<indent;i++)
273+
{
272274
appendStringInfo(str," ");
275+
}
273276
appendStringInfo(str," -> ");
274277
explain_outNode(str,outerPlan(plan),indent+3,es);
275278
}
@@ -278,7 +281,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
278281
if (innerPlan(plan))
279282
{
280283
for (i=0;i<indent;i++)
284+
{
281285
appendStringInfo(str," ");
286+
}
282287
appendStringInfo(str," -> ");
283288
explain_outNode(str,innerPlan(plan),indent+3,es);
284289
}
@@ -290,13 +295,17 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
290295
List*lst;
291296

292297
for (i=0;i<indent;i++)
298+
{
293299
appendStringInfo(str," ");
300+
}
294301
appendStringInfo(str," SubPlan\n");
295302
foreach(lst,plan->subPlan)
296303
{
297304
es->rtable= ((SubPlan*)lfirst(lst))->rtable;
298305
for (i=0;i<indent;i++)
306+
{
299307
appendStringInfo(str," ");
308+
}
300309
appendStringInfo(str," -> ");
301310
explain_outNode(str, ((SubPlan*)lfirst(lst))->plan,indent+4,es);
302311
}
@@ -327,7 +336,9 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
327336
es->rtable=nth(whichplan,appendplan->unionrtables);
328337

329338
for (i=0;i<indent;i++)
339+
{
330340
appendStringInfo(str," ");
341+
}
331342
appendStringInfo(str," -> ");
332343

333344
explain_outNode(str,subnode,indent+4,es);

‎src/backend/commands/user.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: user.c,v 1.21 1998/12/1406:50:18 scrappy Exp $
8+
* $Id: user.c,v 1.22 1998/12/1408:11:00 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
12-
#include<stdio.h>/* for sprintf() */
12+
#include<stdio.h>
1313
#include<string.h>
1414
#include<sys/types.h>
1515
#include<sys/stat.h>
@@ -68,7 +68,7 @@ UpdatePgPwdFile(char *sql)
6868
* SEPCHAR character as the delimiter between fields. Then rename the
6969
* file to its final name.
7070
*/
71-
snprintf(sql,QRY_LENGTH,
71+
snprintf(sql,SQL_LENGTH,
7272
"copy %s to '%s' using delimiters %s",
7373
ShadowRelationName,tempname,CRYPT_PWD_FILE_SEPCHAR);
7474
pg_exec_query(sql);
@@ -173,7 +173,7 @@ DefineUser(CreateUserStmt *stmt)
173173
(stmt->createdb&&*stmt->createdb) ?",'t','t'" :",'f','t'",
174174
(stmt->createuser&&*stmt->createuser) ?",'t','t'" :",'f','t'",
175175
stmt->password ?stmt->password :"''",
176-
stmt->validUntil ?stmt->valudUntil :"");
176+
stmt->validUntil ?stmt->validUntil :"");
177177

178178
pg_exec_query(sql);
179179

@@ -262,20 +262,20 @@ AlterUser(AlterUserStmt *stmt)
262262
if (stmt->createdb)
263263
{
264264
snprintf(sql,SQL_LENGTH,"%s %susecreatedb='%s'",
265-
stmt->password ?"," :"",
266-
*stmt->createdb ?"t" :"f");
265+
sql,stmt->password ?"," :"",*stmt->createdb ?"t" :"f");
267266
}
268267

269268
if (stmt->createuser)
270269
{
271270
snprintf(sql,SQL_LENGTH,"%s %susesuper='%s'",
272-
(stmt->password||stmt->createdb) ?"," :"",
271+
sql,(stmt->password||stmt->createdb) ?"," :"",
273272
*stmt->createuser ?"t" :"f");
274273
}
275274

276275
if (stmt->validUntil)
277276
{
278277
snprintf(sql,SQL_LENGTH,"%s %svaluntil='%s'",
278+
sql,
279279
(stmt->password||stmt->createdb||stmt->createuser) ?"," :"",
280280
stmt->validUntil);
281281
}

‎src/backend/commands/view.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: view.c,v 1.28 1998/12/1406:50:18 scrappy Exp $
8+
* $Id: view.c,v 1.29 1998/12/1408:11:01 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
12-
#include<stdio.h>/* for sprintf() */
12+
#include<stdio.h>
1313
#include<string.h>
1414

1515
#include<postgres.h>

‎src/backend/executor/execAmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: execAmi.c,v 1.27 1998/12/1406:50:20 scrappy Exp $
8+
* $Id: execAmi.c,v 1.28 1998/12/1408:11:02 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -24,7 +24,7 @@
2424
*ExecCreatRfunction to create temporary relations
2525
*
2626
*/
27-
#include<stdio.h>/* for sprintf() */
27+
#include<stdio.h>
2828

2929
#include"postgres.h"
3030

‎src/backend/executor/nodeHash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $Id: nodeHash.c,v 1.26 1998/12/1406:50:21 scrappy Exp $
9+
* $Id: nodeHash.c,v 1.27 1998/12/1408:11:02 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -19,7 +19,7 @@
1919
*/
2020

2121
#include<sys/types.h>
22-
#include<stdio.h>/* for sprintf() */
22+
#include<stdio.h>
2323
#include<math.h>
2424
#include<string.h>
2525
#include<sys/file.h>

‎src/backend/lib/stringinfo.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
/*-------------------------------------------------------------------------
2-
*
1+
/*
32
* stringinfo.c--
43
* These are routines that can be used to write informations to a string,
54
* without having to worry about string lengths, space allocation etc.
65
* Ideally the interface should look like the file i/o interface,
76
*
87
* Copyright (c) 1994, Regents of the University of California
98
*
10-
*
11-
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/lib/stringinfo.c,v 1.12 1998/11/08 19:22:24 tgl Exp $
13-
*
14-
*-------------------------------------------------------------------------
9+
* $Id: stringinfo.c,v 1.13 1998/12/14 08:11:04 scrappy Exp $
1510
*/
11+
12+
#include<stdio.h>
1613
#include<string.h>
1714

15+
#include<stdarg.h>
16+
1817
#include<postgres.h>
1918

2019
#include<nodes/pg_list.h>
2120
#include<lib/stringinfo.h>
2221

23-
/*---------------------------------------------------------------------
22+
/*
2423
* makeStringInfo
2524
*
2625
* Create a StringInfoData & return a pointer to it.
2726
*
28-
*---------------------------------------------------------------------
2927
*/
3028
StringInfo
3129
makeStringInfo()
@@ -52,34 +50,39 @@ makeStringInfo()
5250
returnres;
5351
}
5452

55-
/*---------------------------------------------------------------------
53+
/*
5654
* appendStringInfo
5755
*
5856
* append to the current 'StringInfo' a new string.
5957
* If there is not enough space in the current 'data', then reallocate
6058
* some more...
6159
*
6260
* NOTE: if we reallocate space, we pfree the old one!
63-
*---------------------------------------------------------------------
61+
*
6462
*/
6563
void
66-
appendStringInfo(StringInfostr,char*buffer)
64+
appendStringInfo(StringInfostr,constchar*fmt,...)
6765
{
68-
intbuflen,
66+
intbuflen,
6967
newlen,
7068
needed;
71-
char*s;
69+
char*s,
70+
buffer[512];
71+
72+
va_listargs;
73+
va_start(args,fmt);
74+
buflen=vsnprintf(buffer,512,fmt,args);
75+
va_end(args);
7276

7377
Assert(str!=NULL);
74-
if (buffer==NULL)
75-
buffer="<>";
78+
if (buflen==0)
79+
strcpy(buffer,"<>");
7680

7781
/*
7882
* do we have enough space to append the new string? (don't forget to
7983
* count the null string terminating char!) If no, then reallocate
8084
* some more.
8185
*/
82-
buflen=strlen(buffer);
8386
needed=str->len+buflen+1;
8487
if (needed>str->maxlen)
8588
{
@@ -99,8 +102,7 @@ appendStringInfo(StringInfo str, char *buffer)
99102
if (s==NULL)
100103
{
101104
elog(ERROR,
102-
"appendStringInfo: Out of memory (%d bytes requested)",
103-
newlen);
105+
"appendStringInfo: Out of memory (%d bytes requested)",newlen);
104106
}
105107
/*
106108
* transfer the data. strcpy() would work, but is probably a tad

‎src/backend/libpq/portal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: portal.c,v 1.18 1998/12/1406:50:26 scrappy Exp $
8+
* $Id: portal.c,v 1.19 1998/12/1408:11:06 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -53,7 +53,7 @@
5353
*see utils/mmgr/portalmem.c for why. -cim 2/22/91
5454
*
5555
*/
56-
#include<stdio.h>/* for sprintf() */
56+
#include<stdio.h>
5757
#include<string.h>
5858

5959
#include<postgres.h>

‎src/backend/libpq/util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: util.c,v 1.6 1998/12/1406:50:27 scrappy Exp $
8+
* $Id: util.c,v 1.7 1998/12/1408:11:07 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -17,7 +17,7 @@
1717
*PQuntrace- turn off pqdebug() tracing
1818
*/
1919

20-
#include<stdio.h>/* for sprintf() */
20+
#include<stdio.h>
2121
#include<string.h>
2222

2323
#include<postgres.h>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp