Skip to content

Commit

Permalink
use std::move with vector insertions
Browse files Browse the repository at this point in the history
Coverity has started detecting places where variables are inserted into
a vector via a copy operation, and then not used anymore.  Switch them
over to explicit std::move for quick performance improvements.

For example:
6405         MinidumpCrashpadInfo::AnnotationObject object = {annotation.type, name,
6406                                                          value_data};
>>>     CID 465406:  Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
>>>     "object" is copied and then passed-by-reference as parameter to STL insertion
        function "std::vector<google_breakpad::MinidumpCrashpadInfo::AnnotationObject,
        std::allocator<google_breakpad::MinidumpCrashpadInfo::AnnotationObject> >::push_back(
        std::vector<google_breakpad::MinidumpCrashpadInfo::AnnotationObject,
        std::allocator<google_breakpad::MinidumpCrashpadInfo::AnnotationObject> >::value_type const &)",
         when it could be moved instead.
6407         annotations_list->push_back(object);

Change-Id: I2d3b3a35296dad84853f4dc6690d64c81c92d582
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/6173183
Reviewed-by: Primiano Tucci <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
  • Loading branch information
vapier committed Jan 17, 2025
1 parent feea0f7 commit 41b6533
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/common/dwarf/dwarf2reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void CompilationUnit::ReadAbbrevs() {
value);
abbrev.attributes.push_back(abbrev_attr);
}
abbrevs_->push_back(abbrev);
abbrevs_->push_back(std::move(abbrev));
}

// Account of cases where entries are out of order.
Expand Down
17 changes: 10 additions & 7 deletions src/processor/minidump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5468,9 +5468,12 @@ bool MinidumpCrashpadInfo::Read(uint32_t expected_size) {
module_crashpad_info_links_.push_back(
module_crashpad_info_links[index].minidump_module_list_index);
module_crashpad_info_.push_back(module_crashpad_info);
module_crashpad_info_list_annotations_.push_back(list_annotations);
module_crashpad_info_simple_annotations_.push_back(simple_annotations);
module_crashpad_info_annotation_objects_.push_back(annotation_objects);
module_crashpad_info_list_annotations_.push_back(std::move(
list_annotations));
module_crashpad_info_simple_annotations_.push_back(std::move(
simple_annotations));
module_crashpad_info_annotation_objects_.push_back(std::move(
annotation_objects));
}
}

Expand Down Expand Up @@ -6272,7 +6275,7 @@ bool Minidump::ReadStringList(
return false;
}

string_list->push_back(entry);
string_list->push_back(std::move(entry));
}

return true;
Expand Down Expand Up @@ -6402,9 +6405,9 @@ bool Minidump::ReadCrashpadAnnotationsList(
return false;
}

MinidumpCrashpadInfo::AnnotationObject object = {annotation.type, name,
value_data};
annotations_list->push_back(object);
MinidumpCrashpadInfo::AnnotationObject object{annotation.type, name,
value_data};
annotations_list->push_back(std::move(object));
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/processor/minidump_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ ProcessResult MinidumpProcessor::Process(
stack->set_tid(thread_id);
process_state->threads_.push_back(stack.release());
process_state->thread_memory_regions_.push_back(thread_memory);
process_state->thread_names_.push_back(thread_name);
process_state->thread_names_.push_back(std::move(thread_name));
}

if (interrupted) {
Expand Down
4 changes: 3 additions & 1 deletion src/processor/proc_maps_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <inttypes.h>
#include <stdio.h>

#include <utility>

#include "common/using_std_string.h"
#include "processor/logging.h"

Expand Down Expand Up @@ -99,7 +101,7 @@ bool ParseProcMaps(const string& input,
return false;

// Pushing then assigning saves us a string copy.
regions.push_back(region);
regions.push_back(std::move(region));
regions.back().path.assign(line + path_index);
regions.back().line.assign(line);
}
Expand Down

0 comments on commit 41b6533

Please sign in to comment.