diff options
author | Masahiko Sawada <msawada@postgresql.org> | 2025-03-04 10:38:41 -0800 |
---|---|---|
committer | Masahiko Sawada <msawada@postgresql.org> | 2025-03-04 10:38:41 -0800 |
commit | bacbc4863b3bfb79b9577f11f2c77e4df9f66d66 (patch) | |
tree | dd242c1aa05c18d264f4d3fe5b890018e9e01b3e /src | |
parent | 0b2a45a5d1f2b088640a7eb7817ca6a0513a2717 (diff) | |
download | postgresql-bacbc4863b3bfb79b9577f11f2c77e4df9f66d66.tar.gz postgresql-bacbc4863b3bfb79b9577f11f2c77e4df9f66d66.zip |
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 7717f6300 and 2e4127b6d.
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/copyfrom.c | 8 | ||||
-rw-r--r-- | src/backend/commands/copyto.c | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index 198cee2bc48..bcf66f0adf8 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -153,11 +153,11 @@ static const CopyFromRoutine CopyFromRoutineBinary = { /* Return a COPY FROM routine for the given options */ static const CopyFromRoutine * -CopyFromGetRoutine(CopyFormatOptions opts) +CopyFromGetRoutine(const CopyFormatOptions *opts) { - if (opts.csv_mode) + if (opts->csv_mode) return &CopyFromRoutineCSV; - else if (opts.binary) + else if (opts->binary) return &CopyFromRoutineBinary; /* default is text */ @@ -1574,7 +1574,7 @@ BeginCopyFrom(ParseState *pstate, ProcessCopyOptions(pstate, &cstate->opts, true /* is_from */ , options); /* Set the format routine */ - cstate->routine = CopyFromGetRoutine(cstate->opts); + cstate->routine = CopyFromGetRoutine(&cstate->opts); /* Process the target relation */ cstate->rel = rel; diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index 721d29f8e53..84a3f3879a8 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -174,11 +174,11 @@ static const CopyToRoutine CopyToRoutineBinary = { /* Return a COPY TO routine for the given options */ static const CopyToRoutine * -CopyToGetRoutine(CopyFormatOptions opts) +CopyToGetRoutine(const CopyFormatOptions *opts) { - if (opts.csv_mode) + if (opts->csv_mode) return &CopyToRoutineCSV; - else if (opts.binary) + else if (opts->binary) return &CopyToRoutineBinary; /* default is text */ @@ -700,7 +700,7 @@ BeginCopyTo(ParseState *pstate, ProcessCopyOptions(pstate, &cstate->opts, false /* is_from */ , options); /* Set format routine */ - cstate->routine = CopyToGetRoutine(cstate->opts); + cstate->routine = CopyToGetRoutine(&cstate->opts); /* Process the source/target relation or query */ if (rel) |