Skip to content

Commit f014211

Browse files
authored
disasm: Avoid copying string with passing by reference (KhronosGroup#6757)
Change from value to reference argument passing and store line string value in local value to avoid allocating memory twice.
1 parent 12f9d94 commit f014211

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

source/disassemble.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ spv_result_t DisassembleTargetInstruction(
599599
return SPV_SUCCESS;
600600
}
601601

602-
uint32_t GetLineLengthWithoutColor(const std::string line) {
602+
uint32_t GetLineLengthWithoutColor(const std::string& line) {
603603
// Currently, every added color is in the form \x1b...m, so instead of doing a
604604
// lot of string comparisons with spvtools::clr::* strings, we just ignore
605605
// those ranges.
@@ -804,11 +804,12 @@ void InstructionDisassembler::EmitInstructionImpl(
804804
comment_separator = ", ";
805805
}
806806

807-
stream_ << line.str();
807+
const std::string line_str = line.str();
808+
stream_ << line_str;
808809

809810
if (!comments.str().empty()) {
810811
// Align the comments
811-
const uint32_t line_length = GetLineLengthWithoutColor(line.str());
812+
const uint32_t line_length = GetLineLengthWithoutColor(line_str);
812813
uint32_t align = std::max(
813814
{line_length + 2, last_instruction_comment_alignment_, kCommentColumn});
814815
// Round up the alignment to a multiple of 4 for more niceness.

0 commit comments

Comments
 (0)