Skip to content

Commit 195766b

Browse files
committed
update version to 0.31.1
Minor efficiency gain by using string instead of stringstream
1 parent da946a0 commit 195766b

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

src/ProcessReads.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -536,19 +536,19 @@ void MasterProcessor::writeOutput(std::vector<SplitCode::Results>& rv,
536536
}
537537

538538
if (assigned && (write_barcode_separate_fastq_ || use_pipe) && (!sc->always_assign || (remultiplex && assigned2)) && !no_output_barcodes) { // Write out barcode read
539-
std::stringstream o;
539+
std::string o; o.reserve(1024);
540540
// Write out barcode read
541-
o << start_char << std::string(names[i].first, names[i].second) << mod_name << break_char;
541+
o += start_char + std::string(names[i].first, names[i].second) + mod_name + std::string(1, break_char);
542542
if (!remultiplex) {
543-
o << sc->binaryToString(sc->getID(r.id), sc->getBarcodeLength()) << break_char;
543+
o += sc->binaryToString(sc->getID(r.id), sc->getBarcodeLength()) + std::string(1, break_char);
544544
} else { // Write out remultiplexing barcode
545-
o << sc->binaryToString(sc->getID(batch_id_mapping[flags[readnum]]), sc->getBarcodeLength()) << break_char;
545+
o += sc->binaryToString(sc->getID(batch_id_mapping[flags[readnum]]), sc->getBarcodeLength()) + std::string(1, break_char);
546546
}
547547
if (include_quals) {
548-
o << "+" << break_char;
549-
o << std::string(sc->getBarcodeLength(), sc->QUAL) << break_char;
548+
o += "+" + std::string(1, break_char);
549+
o += std::string(sc->getBarcodeLength(), sc->QUAL) + std::string(1, break_char);
550550
}
551-
const std::string& ostr = o.str();
551+
const std::string& ostr = o;
552552
size_t ostr_len = ostr.length();
553553
if (!outbam || !r.ofile.empty()) { // Only write barcode read if we're not writing BAM files (or we're writing BAM files but we need to write the current read into a FASTQ file for the "keep" demultiplexing)
554554
if (use_pipe && !write_barcode_separate_fastq_) {
@@ -579,14 +579,14 @@ void MasterProcessor::writeOutput(std::vector<SplitCode::Results>& rv,
579579
}
580580
curr_umi = opt.empty_read_sequence;
581581
}
582-
std::stringstream o;
583-
o << start_char << std::string(names[i].first, names[i].second) << mod_name << break_char;
584-
o << curr_umi << break_char;
582+
std::string o; o.reserve(1024);
583+
o += start_char + std::string(names[i].first, names[i].second) + mod_name + std::string(1, break_char);
584+
o += curr_umi + std::string(1, break_char);
585585
if (include_quals) {
586-
o << "+" << break_char;
587-
o << std::string(curr_umi.length(), sc->QUAL) << break_char;
586+
o += "+" + std::string(1, break_char);
587+
o += std::string(curr_umi.length(), sc->QUAL) + std::string(1, break_char);
588588
}
589-
const std::string& ostr = o.str();
589+
const std::string& ostr = o;
590590
size_t ostr_len = ostr.length();
591591
if (use_pipe) {
592592
if (!opt.no_output_) {
@@ -652,7 +652,7 @@ void MasterProcessor::writeOutput(std::vector<SplitCode::Results>& rv,
652652
}
653653

654654
jj++;
655-
std::stringstream o;
655+
std::string o; o.reserve(1024);
656656
const char* s = s_[j];
657657
const char* q = q_[j];
658658
int l = l_[j];
@@ -666,9 +666,8 @@ void MasterProcessor::writeOutput(std::vector<SplitCode::Results>& rv,
666666
);
667667
// Write out read
668668
bool embed_final_barcode = assigned && jj == 0 && !write_barcode_separate_fastq_ && !use_pipe && (!sc->always_assign || remultiplex) && !no_output_barcodes;
669-
std::string embed_placement_str;
670-
o << start_char;
671-
o << std::string(n,nl) << mod_name << break_char;
669+
o += start_char;
670+
o += std::string(n,nl) + mod_name + std::string(1, break_char);
672671
// Insert placement begin
673672
std::string o_str_inserted;
674673
std::string q_str_inserted;
@@ -700,28 +699,28 @@ void MasterProcessor::writeOutput(std::vector<SplitCode::Results>& rv,
700699
// End insert placement
701700
if (embed_final_barcode) {
702701
if (!remultiplex) {
703-
o << sc->binaryToString(sc->getID(r.id), sc->getBarcodeLength());
702+
o += sc->binaryToString(sc->getID(r.id), sc->getBarcodeLength());
704703
} else {
705-
o << sc->binaryToString(sc->getID(batch_id_mapping[flags[readnum]]), sc->getBarcodeLength());
704+
o += sc->binaryToString(sc->getID(batch_id_mapping[flags[readnum]]), sc->getBarcodeLength());
706705
}
707706
} else if (l == 0 && !opt.empty_read_sequence.empty() && !do_insertion) {
708-
o << opt.empty_read_sequence;
707+
o += opt.empty_read_sequence;
709708
} else if (l == 0 && empty_remove && !do_insertion) {
710709
continue; // Don't write anything
711710
}
712-
if (do_insertion) o << o_str_inserted << break_char;
713-
else o << std::string(s,l) << break_char;
711+
if (do_insertion) o += o_str_inserted + std::string(1, break_char);
712+
else o += std::string(s,l) + std::string(1, break_char);
714713
if (include_quals) {
715-
o << "+" << break_char;
714+
o += "+" + std::string(1, break_char);
716715
if (embed_final_barcode) {
717-
o << std::string(sc->getBarcodeLength(), sc->QUAL);
716+
o += std::string(sc->getBarcodeLength(), sc->QUAL);
718717
} else if (l == 0 && !opt.empty_read_sequence.empty()) {
719-
o << std::string(opt.empty_read_sequence.length(), sc->QUAL);
718+
o += std::string(opt.empty_read_sequence.length(), sc->QUAL);
720719
}
721-
if (do_insertion) o << q_str_inserted << break_char;
722-
else o << std::string(q,l) << break_char;
720+
if (do_insertion) o += q_str_inserted + std::string(1, break_char);
721+
else o += std::string(q,l) + std::string(1, break_char);
723722
}
724-
const std::string& ostr = o.str();
723+
const std::string& ostr = o;
725724
size_t ostr_len = ostr.length();
726725
if (assigned2) {
727726
if (outbam && r.ofile.empty()) {

src/SplitCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SPLITCODE_H
22
#define SPLITCODE_H
33

4-
#define SPLITCODE_VERSION "0.31.0"
4+
#define SPLITCODE_VERSION "0.31.1"
55

66
#include <string>
77
#include <iostream>

0 commit comments

Comments
 (0)