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

Commit0d79c0a

Browse files
committed
Make various variables const (read-only).
These changes should generally improve correctness/maintainability.A nice side benefit is that several kilobytes move from initializeddata to text segment, allowing them to be shared across processes andprobably reducing copy-on-write overhead while forking a new backend.Unfortunately this doesn't seem to help libpq in the same way (at leastnot when it's compiled with -fpic on x86_64), but we can hope the linkerat least collects all nominally-const data together even if it's notactually part of the text segment.Also, make pg_encname_tbl[] static in encnames.c, since there seemsno very good reason for any other code to use it; per a suggestionfrom Wim Lewis, who independently submitted a patch that was mostlya subset of this one.Oskari Saarenmaa, with some editorialization by me
1 parent7d7eee8 commit0d79c0a

File tree

16 files changed

+101
-130
lines changed

16 files changed

+101
-130
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ typedef struct
101101
* class? */
102102
}ObjectPropertyType;
103103

104-
staticObjectPropertyTypeObjectProperty[]=
104+
staticconstObjectPropertyTypeObjectProperty[]=
105105
{
106106
{
107107
CastRelationId,
@@ -431,7 +431,7 @@ static ObjectAddress get_object_address_type(ObjectType objtype,
431431
List*objname,boolmissing_ok);
432432
staticObjectAddressget_object_address_opcf(ObjectTypeobjtype,List*objname,
433433
List*objargs,boolmissing_ok);
434-
staticObjectPropertyType*get_object_property_data(Oidclass_id);
434+
staticconstObjectPropertyType*get_object_property_data(Oidclass_id);
435435

436436
staticvoidgetRelationDescription(StringInfobuffer,Oidrelid);
437437
staticvoidgetOpFamilyDescription(StringInfobuffer,Oidopfid);
@@ -1297,7 +1297,7 @@ get_object_namespace(const ObjectAddress *address)
12971297
HeapTupletuple;
12981298
boolisnull;
12991299
Oidoid;
1300-
ObjectPropertyType*property;
1300+
constObjectPropertyType*property;
13011301

13021302
/* If not owned by a namespace, just return InvalidOid. */
13031303
property=get_object_property_data(address->classId);
@@ -1329,71 +1329,71 @@ get_object_namespace(const ObjectAddress *address)
13291329
Oid
13301330
get_object_oid_index(Oidclass_id)
13311331
{
1332-
ObjectPropertyType*prop=get_object_property_data(class_id);
1332+
constObjectPropertyType*prop=get_object_property_data(class_id);
13331333

13341334
returnprop->oid_index_oid;
13351335
}
13361336

13371337
int
13381338
get_object_catcache_oid(Oidclass_id)
13391339
{
1340-
ObjectPropertyType*prop=get_object_property_data(class_id);
1340+
constObjectPropertyType*prop=get_object_property_data(class_id);
13411341

13421342
returnprop->oid_catcache_id;
13431343
}
13441344

13451345
int
13461346
get_object_catcache_name(Oidclass_id)
13471347
{
1348-
ObjectPropertyType*prop=get_object_property_data(class_id);
1348+
constObjectPropertyType*prop=get_object_property_data(class_id);
13491349

13501350
returnprop->name_catcache_id;
13511351
}
13521352

13531353
AttrNumber
13541354
get_object_attnum_name(Oidclass_id)
13551355
{
1356-
ObjectPropertyType*prop=get_object_property_data(class_id);
1356+
constObjectPropertyType*prop=get_object_property_data(class_id);
13571357

13581358
returnprop->attnum_name;
13591359
}
13601360

13611361
AttrNumber
13621362
get_object_attnum_namespace(Oidclass_id)
13631363
{
1364-
ObjectPropertyType*prop=get_object_property_data(class_id);
1364+
constObjectPropertyType*prop=get_object_property_data(class_id);
13651365

13661366
returnprop->attnum_namespace;
13671367
}
13681368

13691369
AttrNumber
13701370
get_object_attnum_owner(Oidclass_id)
13711371
{
1372-
ObjectPropertyType*prop=get_object_property_data(class_id);
1372+
constObjectPropertyType*prop=get_object_property_data(class_id);
13731373

13741374
returnprop->attnum_owner;
13751375
}
13761376

13771377
AttrNumber
13781378
get_object_attnum_acl(Oidclass_id)
13791379
{
1380-
ObjectPropertyType*prop=get_object_property_data(class_id);
1380+
constObjectPropertyType*prop=get_object_property_data(class_id);
13811381

13821382
returnprop->attnum_acl;
13831383
}
13841384

13851385
AclObjectKind
13861386
get_object_aclkind(Oidclass_id)
13871387
{
1388-
ObjectPropertyType*prop=get_object_property_data(class_id);
1388+
constObjectPropertyType*prop=get_object_property_data(class_id);
13891389

13901390
returnprop->acl_kind;
13911391
}
13921392

13931393
bool
13941394
get_object_namensp_unique(Oidclass_id)
13951395
{
1396-
ObjectPropertyType*prop=get_object_property_data(class_id);
1396+
constObjectPropertyType*prop=get_object_property_data(class_id);
13971397

13981398
returnprop->is_nsp_name_unique;
13991399
}
@@ -1419,10 +1419,10 @@ is_objectclass_supported(Oid class_id)
14191419
/*
14201420
* Find ObjectProperty structure by class_id.
14211421
*/
1422-
staticObjectPropertyType*
1422+
staticconstObjectPropertyType*
14231423
get_object_property_data(Oidclass_id)
14241424
{
1425-
staticObjectPropertyType*prop_last=NULL;
1425+
staticconstObjectPropertyType*prop_last=NULL;
14261426
intindex;
14271427

14281428
/*

‎src/backend/commands/conversioncmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ CreateConversionCommand(CreateConversionStmt *stmt)
4646
constchar*from_encoding_name=stmt->for_encoding_name;
4747
constchar*to_encoding_name=stmt->to_encoding_name;
4848
List*func_name=stmt->func_name;
49-
staticOidfuncargs[]= {INT4OID,INT4OID,CSTRINGOID,INTERNALOID,INT4OID};
49+
staticconstOidfuncargs[]= {INT4OID,INT4OID,CSTRINGOID,INTERNALOID,INT4OID};
5050
charresult[1];
5151

5252
/* Convert list of names to a name and namespace */

‎src/backend/regex/regc_lex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ static int/* not actually used, but convenient for RETV */
716716
lexescape(structvars*v)
717717
{
718718
chrc;
719-
staticchralert[]= {
719+
staticconstchralert[]= {
720720
CHR('a'),CHR('l'),CHR('e'),CHR('r'),CHR('t')
721721
};
722-
staticchresc[]= {
722+
staticconstchresc[]= {
723723
CHR('E'),CHR('S'),CHR('C')
724724
};
725725
constchr*save;

‎src/backend/regex/regcomp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ struct vars
274274

275275

276276
/* static function list */
277-
staticstructfnsfunctions= {
277+
staticconststructfnsfunctions= {
278278
rfree,/* regfree insides */
279279
};
280280

‎src/backend/regex/regerror.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#include"regex/regguts.h"
3535

3636
/* unknown-error explanation */
37-
staticcharunk[]="*** unknown regex error code 0x%x ***";
37+
staticconstcharunk[]="*** unknown regex error code 0x%x ***";
3838

3939
/* struct to map among codes, code names, and explanations */
40-
staticstructrerr
40+
staticconststructrerr
4141
{
4242
intcode;
4343
constchar*name;
@@ -62,7 +62,7 @@ pg_regerror(int errcode,/* error code, or REG_ATOI or REG_ITOA */
6262
char*errbuf,/* result buffer (unless errbuf_size==0) */
6363
size_terrbuf_size)/* available space in errbuf, can be 0 */
6464
{
65-
structrerr*r;
65+
conststructrerr*r;
6666
constchar*msg;
6767
charconvbuf[sizeof(unk)+50];/* 50 = plenty for int */
6868
size_tlen;

‎src/backend/tsearch/wparser_def.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ p_isspecial(TParser *prs)
789789
*/
790790
if (GetDatabaseEncoding()==PG_UTF8&&prs->usewide)
791791
{
792-
staticpg_wcharstrange_letter[]= {
792+
staticconstpg_wcharstrange_letter[]= {
793793
/*
794794
* use binary search, so elements should be ordered
795795
*/
@@ -1023,7 +1023,7 @@ p_isspecial(TParser *prs)
10231023
0xAA34,/* CHAM CONSONANT SIGN RA */
10241024
0xAA4D/* CHAM CONSONANT SIGN FINAL H */
10251025
};
1026-
pg_wchar*StopLow=strange_letter,
1026+
constpg_wchar*StopLow=strange_letter,
10271027
*StopHigh=strange_letter+lengthof(strange_letter),
10281028
*StopMiddle;
10291029
pg_wcharc;

‎src/backend/utils/adt/datetime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ const intday_tab[2][13] =
5959
{31,29,31,30,31,30,31,31,30,31,30,31,0}
6060
};
6161

62-
char*months[]= {"Jan","Feb","Mar","Apr","May","Jun",
62+
constchar*constmonths[]= {"Jan","Feb","Mar","Apr","May","Jun",
6363
"Jul","Aug","Sep","Oct","Nov","Dec",NULL};
6464

65-
char*days[]= {"Sunday","Monday","Tuesday","Wednesday",
65+
constchar*constdays[]= {"Sunday","Monday","Tuesday","Wednesday",
6666
"Thursday","Friday","Saturday",NULL};
6767

6868

@@ -186,7 +186,7 @@ static const datetkn datetktbl[] = {
186186

187187
staticintszdatetktbl=sizeofdatetktbl /sizeofdatetktbl[0];
188188

189-
staticdatetkndeltatktbl[]= {
189+
staticconstdatetkndeltatktbl[]= {
190190
/* text, token, lexval */
191191
{"@",IGNORE_DTF,0},/* postgres relative prefix */
192192
{DAGO,AGO,0},/* "ago" indicates negative time offset */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp