diff options
author | Robert Haas <rhaas@postgresql.org> | 2013-12-02 10:51:06 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2013-12-02 10:51:06 -0500 |
commit | a8656a3ab02db5b1de0d696dc8cf588efe7c1341 (patch) | |
tree | 47d2bf72c28cb10b941c0ee8b7e5fbb5d903f851 /src/backend/utils/adt/formatting.c | |
parent | 9d140f7be2836e3baf6c9dc7989dea69ef693532 (diff) | |
download | postgresql-a8656a3ab02db5b1de0d696dc8cf588efe7c1341.tar.gz postgresql-a8656a3ab02db5b1de0d696dc8cf588efe7c1341.zip |
Make NUM_TOCHAR_prepare and NUM_TOCHAR_finish macros declare "len".
Remove the variable from the enclosing scopes so that nothing can be
relying on it. The net result of this refactoring is that we get rid
of a few unnecessary strlen() calls.
Original patch from Greg Jaskiewicz, substantially expanded by me.
Diffstat (limited to 'src/backend/utils/adt/formatting.c')
-rw-r--r-- | src/backend/utils/adt/formatting.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index 36353c39c16..946f3e28c65 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -4877,7 +4877,7 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number, */ #define NUM_TOCHAR_prepare \ do { \ - len = VARSIZE_ANY_EXHDR(fmt); \ + int len = VARSIZE_ANY_EXHDR(fmt); \ if (len <= 0 || len >= (INT_MAX-VARHDRSZ)/NUM_MAX_ITEM_SIZ) \ PG_RETURN_TEXT_P(cstring_to_text("")); \ result = (text *) palloc0((len * NUM_MAX_ITEM_SIZ) + 1 + VARHDRSZ); \ @@ -4890,6 +4890,8 @@ do { \ */ #define NUM_TOCHAR_finish \ do { \ + int len; \ + \ NUM_processor(format, &Num, VARDATA(result), numstr, plen, sign, true, PG_GET_COLLATION()); \ \ if (shouldFree) \ @@ -4961,8 +4963,7 @@ numeric_to_char(PG_FUNCTION_ARGS) FormatNode *format; text *result; bool shouldFree; - int len = 0, - plen = 0, + int plen = 0, sign = 0; char *numstr, *orgnum, @@ -5008,16 +5009,15 @@ numeric_to_char(PG_FUNCTION_ARGS) numstr = (char *) palloc(strlen(orgnum) + 2); *numstr = ' '; strcpy(numstr + 1, orgnum); - len = strlen(numstr); } else { numstr = orgnum; - len = strlen(orgnum); } } else { + int len; Numeric val = value; if (IS_MULTI(&Num)) @@ -5084,8 +5084,7 @@ int4_to_char(PG_FUNCTION_ARGS) FormatNode *format; text *result; bool shouldFree; - int len = 0, - plen = 0, + int plen = 0, sign = 0; char *numstr, *orgnum; @@ -5111,11 +5110,12 @@ int4_to_char(PG_FUNCTION_ARGS) if (*orgnum == '+') *orgnum = ' '; - len = strlen(orgnum); numstr = orgnum; } else { + int len; + if (IS_MULTI(&Num)) { orgnum = DatumGetCString(DirectFunctionCall1(int4out, @@ -5175,8 +5175,7 @@ int8_to_char(PG_FUNCTION_ARGS) FormatNode *format; text *result; bool shouldFree; - int len = 0, - plen = 0, + int plen = 0, sign = 0; char *numstr, *orgnum; @@ -5211,16 +5210,16 @@ int8_to_char(PG_FUNCTION_ARGS) numstr = (char *) palloc(strlen(orgnum) + 2); *numstr = ' '; strcpy(numstr + 1, orgnum); - len = strlen(numstr); } else { numstr = orgnum; - len = strlen(orgnum); } } else { + int len; + if (IS_MULTI(&Num)) { double multi = pow((double) 10, (double) Num.multi); @@ -5282,8 +5281,7 @@ float4_to_char(PG_FUNCTION_ARGS) FormatNode *format; text *result; bool shouldFree; - int len = 0, - plen = 0, + int plen = 0, sign = 0; char *numstr, *orgnum, @@ -5317,13 +5315,13 @@ float4_to_char(PG_FUNCTION_ARGS) if (*orgnum == '+') *orgnum = ' '; - len = strlen(orgnum); numstr = orgnum; } } else { float4 val = value; + int len; if (IS_MULTI(&Num)) { @@ -5386,8 +5384,7 @@ float8_to_char(PG_FUNCTION_ARGS) FormatNode *format; text *result; bool shouldFree; - int len = 0, - plen = 0, + int plen = 0, sign = 0; char *numstr, *orgnum, @@ -5421,13 +5418,13 @@ float8_to_char(PG_FUNCTION_ARGS) if (*orgnum == '+') *orgnum = ' '; - len = strlen(orgnum); numstr = orgnum; } } else { float8 val = value; + int len; if (IS_MULTI(&Num)) { |