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

Commita8656a3

Browse files
committed
Make NUM_TOCHAR_prepare and NUM_TOCHAR_finish macros declare "len".
Remove the variable from the enclosing scopes so that nothing can berelying on it. The net result of this refactoring is that we get ridof a few unnecessary strlen() calls.Original patch from Greg Jaskiewicz, substantially expanded by me.
1 parent9d140f7 commita8656a3

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,7 +4877,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
48774877
*/
48784878
#defineNUM_TOCHAR_prepare \
48794879
do { \
4880-
len = VARSIZE_ANY_EXHDR(fmt); \
4880+
intlen = VARSIZE_ANY_EXHDR(fmt); \
48814881
if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ)\
48824882
PG_RETURN_TEXT_P(cstring_to_text("")); \
48834883
result= (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ);\
@@ -4890,6 +4890,8 @@ do { \
48904890
*/
48914891
#defineNUM_TOCHAR_finish \
48924892
do { \
4893+
intlen; \
4894+
\
48934895
NUM_processor(format, &Num, VARDATA(result), numstr, plen, sign, true, PG_GET_COLLATION()); \
48944896
\
48954897
if (shouldFree)\
@@ -4961,8 +4963,7 @@ numeric_to_char(PG_FUNCTION_ARGS)
49614963
FormatNode*format;
49624964
text*result;
49634965
boolshouldFree;
4964-
intlen=0,
4965-
plen=0,
4966+
intplen=0,
49664967
sign=0;
49674968
char*numstr,
49684969
*orgnum,
@@ -5008,16 +5009,15 @@ numeric_to_char(PG_FUNCTION_ARGS)
50085009
numstr= (char*)palloc(strlen(orgnum)+2);
50095010
*numstr=' ';
50105011
strcpy(numstr+1,orgnum);
5011-
len=strlen(numstr);
50125012
}
50135013
else
50145014
{
50155015
numstr=orgnum;
5016-
len=strlen(orgnum);
50175016
}
50185017
}
50195018
else
50205019
{
5020+
intlen;
50215021
Numericval=value;
50225022

50235023
if (IS_MULTI(&Num))
@@ -5084,8 +5084,7 @@ int4_to_char(PG_FUNCTION_ARGS)
50845084
FormatNode*format;
50855085
text*result;
50865086
boolshouldFree;
5087-
intlen=0,
5088-
plen=0,
5087+
intplen=0,
50895088
sign=0;
50905089
char*numstr,
50915090
*orgnum;
@@ -5111,11 +5110,12 @@ int4_to_char(PG_FUNCTION_ARGS)
51115110
if (*orgnum=='+')
51125111
*orgnum=' ';
51135112

5114-
len=strlen(orgnum);
51155113
numstr=orgnum;
51165114
}
51175115
else
51185116
{
5117+
intlen;
5118+
51195119
if (IS_MULTI(&Num))
51205120
{
51215121
orgnum=DatumGetCString(DirectFunctionCall1(int4out,
@@ -5175,8 +5175,7 @@ int8_to_char(PG_FUNCTION_ARGS)
51755175
FormatNode*format;
51765176
text*result;
51775177
boolshouldFree;
5178-
intlen=0,
5179-
plen=0,
5178+
intplen=0,
51805179
sign=0;
51815180
char*numstr,
51825181
*orgnum;
@@ -5211,16 +5210,16 @@ int8_to_char(PG_FUNCTION_ARGS)
52115210
numstr= (char*)palloc(strlen(orgnum)+2);
52125211
*numstr=' ';
52135212
strcpy(numstr+1,orgnum);
5214-
len=strlen(numstr);
52155213
}
52165214
else
52175215
{
52185216
numstr=orgnum;
5219-
len=strlen(orgnum);
52205217
}
52215218
}
52225219
else
52235220
{
5221+
intlen;
5222+
52245223
if (IS_MULTI(&Num))
52255224
{
52265225
doublemulti=pow((double)10, (double)Num.multi);
@@ -5282,8 +5281,7 @@ float4_to_char(PG_FUNCTION_ARGS)
52825281
FormatNode*format;
52835282
text*result;
52845283
boolshouldFree;
5285-
intlen=0,
5286-
plen=0,
5284+
intplen=0,
52875285
sign=0;
52885286
char*numstr,
52895287
*orgnum,
@@ -5317,13 +5315,13 @@ float4_to_char(PG_FUNCTION_ARGS)
53175315
if (*orgnum=='+')
53185316
*orgnum=' ';
53195317

5320-
len=strlen(orgnum);
53215318
numstr=orgnum;
53225319
}
53235320
}
53245321
else
53255322
{
53265323
float4val=value;
5324+
intlen;
53275325

53285326
if (IS_MULTI(&Num))
53295327
{
@@ -5386,8 +5384,7 @@ float8_to_char(PG_FUNCTION_ARGS)
53865384
FormatNode*format;
53875385
text*result;
53885386
boolshouldFree;
5389-
intlen=0,
5390-
plen=0,
5387+
intplen=0,
53915388
sign=0;
53925389
char*numstr,
53935390
*orgnum,
@@ -5421,13 +5418,13 @@ float8_to_char(PG_FUNCTION_ARGS)
54215418
if (*orgnum=='+')
54225419
*orgnum=' ';
54235420

5424-
len=strlen(orgnum);
54255421
numstr=orgnum;
54265422
}
54275423
}
54285424
else
54295425
{
54305426
float8val=value;
5427+
intlen;
54315428

54325429
if (IS_MULTI(&Num))
54335430
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp