Skip to content

Commit b9179f7

Browse files
nw_aligner: store cigar in Result as char const * instead of std::string&
Avoids the cppcoreguidelines-avoid-const-or-ref-data-members warning on Result::cigar_string. Both callers only used .data(); semantics (pointer into NwAligner's internal buffer, invalidated by the next align() call) are unchanged. Co-Authored-By: Florian Filloux <ffillouxdev@users.noreply.github.com>
1 parent e5d7ee9 commit b9179f7

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/algo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ namespace {
474474

475475
std::fprintf(parameters.uclustfile.get(), "H\t%u\t%u\t%.1f\t+\t0\t0\t%s\t",
476476
swarmid - 1, hit_seq.length, result.percent_id,
477-
result.differences > 0 ? result.cigar_string.data() : "=");
477+
result.differences > 0 ? result.cigar_string : "=");
478478

479479
data.fprint_id(parameters.uclustfile.get(), hit, parameters.opt_usearch_abundance, parameters.opt_append_abundance);
480480
std::fprintf(parameters.uclustfile.get(), "\t");

src/algod1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ namespace {
993993
cluster_no,
994994
amp_seq.length,
995995
result.percent_id,
996-
result.differences > 0 ? result.cigar_string.data() : "=");
996+
result.differences > 0 ? result.cigar_string : "=");
997997

998998
data.fprint_id(parameters.uclustfile.get(), amp_id, parameters.opt_usearch_abundance, parameters.opt_append_abundance);
999999
std::fprintf(parameters.uclustfile.get(), "\t");

src/utils/nw_aligner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,5 @@ auto NwAligner::align(Sequence const & dseq, Sequence const & qseq) -> NwAligner
274274
auto const percent_id =
275275
one_hundred * static_cast<double>(length - nwdiff) / static_cast<double>(length);
276276

277-
return Result{cigar_string_, nwdiff, length, percent_id};
277+
return Result{cigar_string_.data(), nwdiff, length, percent_id};
278278
}

src/utils/nw_aligner.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct Sequence; // defined in db.h
4444
4545
align() returns a small Result aggregating the four values consumers
4646
need: cigar string, number of differences, alignment length, and
47-
percent identity. The cigar_string reference lives in this NwAligner
47+
percent identity. The cigar_string pointer lives in this NwAligner
4848
object's internal buffer and is only valid until the next align()
4949
call on the same object.
5050
*/
@@ -59,10 +59,10 @@ class NwAligner {
5959
};
6060

6161
struct Result {
62-
std::string const & cigar_string;
63-
uint64_t differences;
64-
uint64_t length; // == nwalignmentlength
65-
double percent_id;
62+
char const * cigar_string;
63+
uint64_t differences;
64+
uint64_t length; // == nwalignmentlength
65+
double percent_id;
6666
};
6767

6868
NwAligner(uint64_t longest_sequence,

0 commit comments

Comments
 (0)