Tweak: use memcpy() in text_time(), rather than manually copying bytes
in a loop.
This commit is contained in:
parent
85df43f341
commit
f14f27dd38
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.129 2007/02/27 23:48:07 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.130 2007/05/30 19:38:05 neilc Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -1635,7 +1635,7 @@ time_text(PG_FUNCTION_ARGS)
|
|||||||
result = palloc(len);
|
result = palloc(len);
|
||||||
|
|
||||||
SET_VARSIZE(result, len);
|
SET_VARSIZE(result, len);
|
||||||
memcpy(VARDATA(result), str, (len - VARHDRSZ));
|
memcpy(VARDATA(result), str, len - VARHDRSZ);
|
||||||
|
|
||||||
pfree(str);
|
pfree(str);
|
||||||
|
|
||||||
@ -1651,11 +1651,9 @@ time_text(PG_FUNCTION_ARGS)
|
|||||||
Datum
|
Datum
|
||||||
text_time(PG_FUNCTION_ARGS)
|
text_time(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
text *str = PG_GETARG_TEXT_P(0);
|
text *str = PG_GETARG_TEXT_P(0);
|
||||||
int i;
|
char dstr[MAXDATELEN + 1];
|
||||||
char *sp,
|
size_t len;
|
||||||
*dp,
|
|
||||||
dstr[MAXDATELEN + 1];
|
|
||||||
|
|
||||||
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
|
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
@ -1663,11 +1661,9 @@ text_time(PG_FUNCTION_ARGS)
|
|||||||
errmsg("invalid input syntax for type time: \"%s\"",
|
errmsg("invalid input syntax for type time: \"%s\"",
|
||||||
VARDATA(str))));
|
VARDATA(str))));
|
||||||
|
|
||||||
sp = VARDATA(str);
|
len = VARSIZE(str) - VARHDRSZ;
|
||||||
dp = dstr;
|
memcpy(dstr, VARDATA(str), len);
|
||||||
for (i = 0; i < (VARSIZE(str) - VARHDRSZ); i++)
|
dstr[len] = '\0';
|
||||||
*dp++ = *sp++;
|
|
||||||
*dp = '\0';
|
|
||||||
|
|
||||||
return DirectFunctionCall3(time_in,
|
return DirectFunctionCall3(time_in,
|
||||||
CStringGetDatum(dstr),
|
CStringGetDatum(dstr),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user