Skip to content

Commit f14f27d

Browse files
author
Neil Conway
committed
Tweak: use memcpy() in text_time(), rather than manually copying bytes
in a loop.
1 parent 85df43f commit f14f27d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/backend/utils/adt/date.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.129 2007/02/27 23:48:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.130 2007/05/30 19:38:05 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1635,7 +1635,7 @@ time_text(PG_FUNCTION_ARGS)
16351635
result = palloc(len);
16361636

16371637
SET_VARSIZE(result, len);
1638-
memcpy(VARDATA(result), str, (len - VARHDRSZ));
1638+
memcpy(VARDATA(result), str, len - VARHDRSZ);
16391639

16401640
pfree(str);
16411641

@@ -1651,23 +1651,19 @@ time_text(PG_FUNCTION_ARGS)
16511651
Datum
16521652
text_time(PG_FUNCTION_ARGS)
16531653
{
1654-
text *str = PG_GETARG_TEXT_P(0);
1655-
int i;
1656-
char *sp,
1657-
*dp,
1658-
dstr[MAXDATELEN + 1];
1654+
text *str = PG_GETARG_TEXT_P(0);
1655+
char dstr[MAXDATELEN + 1];
1656+
size_t len;
16591657

16601658
if (VARSIZE(str) - VARHDRSZ > MAXDATELEN)
16611659
ereport(ERROR,
16621660
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
16631661
errmsg("invalid input syntax for type time: \"%s\"",
16641662
VARDATA(str))));
16651663

1666-
sp = VARDATA(str);
1667-
dp = dstr;
1668-
for (i = 0; i < (VARSIZE(str) - VARHDRSZ); i++)
1669-
*dp++ = *sp++;
1670-
*dp = '\0';
1664+
len = VARSIZE(str) - VARHDRSZ;
1665+
memcpy(dstr, VARDATA(str), len);
1666+
dstr[len] = '\0';
16711667

16721668
return DirectFunctionCall3(time_in,
16731669
CStringGetDatum(dstr),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy