Skip to content

Commit bacbc48

Browse files
Refactor Copy{From|To}GetRoutine() to use pass-by-reference argument.
The change improves efficiency by eliminating unnecessary copying of CopyFormatOptions. The coverity also complained about inefficiencies caused by pass-by-value. Oversight in 7717f63 and 2e4127b. Reported-by: Junwang Zhao <zhjwpku@gmail.com> Reported-by: Tom Lane <tgl@sss.pgh.pa.us> (per reports from coverity) Author: Sutou Kouhei <kou@clear-code.com> Reviewed-by: Junwang Zhao <zhjwpku@gmail.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/CAEG8a3L6YCpPksTQMzjD_CvwDEhW3D_t=5md9BvvdOs5k+TA=Q@mail.gmail.com
1 parent 0b2a45a commit bacbc48

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/backend/commands/copyfrom.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ static const CopyFromRoutine CopyFromRoutineBinary = {
153153

154154
/* Return a COPY FROM routine for the given options */
155155
static const CopyFromRoutine *
156-
CopyFromGetRoutine(CopyFormatOptions opts)
156+
CopyFromGetRoutine(const CopyFormatOptions *opts)
157157
{
158-
if (opts.csv_mode)
158+
if (opts->csv_mode)
159159
return &CopyFromRoutineCSV;
160-
else if (opts.binary)
160+
else if (opts->binary)
161161
return &CopyFromRoutineBinary;
162162

163163
/* default is text */
@@ -1574,7 +1574,7 @@ BeginCopyFrom(ParseState *pstate,
15741574
ProcessCopyOptions(pstate, &cstate->opts, true /* is_from */ , options);
15751575

15761576
/* Set the format routine */
1577-
cstate->routine = CopyFromGetRoutine(cstate->opts);
1577+
cstate->routine = CopyFromGetRoutine(&cstate->opts);
15781578

15791579
/* Process the target relation */
15801580
cstate->rel = rel;

src/backend/commands/copyto.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ static const CopyToRoutine CopyToRoutineBinary = {
174174

175175
/* Return a COPY TO routine for the given options */
176176
static const CopyToRoutine *
177-
CopyToGetRoutine(CopyFormatOptions opts)
177+
CopyToGetRoutine(const CopyFormatOptions *opts)
178178
{
179-
if (opts.csv_mode)
179+
if (opts->csv_mode)
180180
return &CopyToRoutineCSV;
181-
else if (opts.binary)
181+
else if (opts->binary)
182182
return &CopyToRoutineBinary;
183183

184184
/* default is text */
@@ -700,7 +700,7 @@ BeginCopyTo(ParseState *pstate,
700700
ProcessCopyOptions(pstate, &cstate->opts, false /* is_from */ , options);
701701

702702
/* Set format routine */
703-
cstate->routine = CopyToGetRoutine(cstate->opts);
703+
cstate->routine = CopyToGetRoutine(&cstate->opts);
704704

705705
/* Process the source/target relation or query */
706706
if (rel)

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