Skip to content

Commit

Permalink
use const string& in more places to avoid unnecessary copy constructors
Browse files Browse the repository at this point in the history
Coverity has started checking for wasteful copies where move's would
work which has pointed out a bunch of places where we use "string" in
a function prototype even though it's always read-only.  Convert all
those over to "const string&" for simple performance improvements.

Change-Id: I264b19c1de8d2d0aa69032bff44cea95cc057a70
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/6173849
Reviewed-by: Nelson Billing <[email protected]>
  • Loading branch information
vapier committed Jan 15, 2025
1 parent 69621cb commit feea0f7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/client/linux/handler/exception_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static bool InstallRaiseSIGKILL() {

static void CrashWithCallbacks(ExceptionHandler::FilterCallback filter,
ExceptionHandler::MinidumpCallback done,
string path) {
const string& path) {
ExceptionHandler handler(
MinidumpDescriptor(path), filter, done, NULL, true, -1);
// Crash with the exception handler in scope.
Expand Down
2 changes: 1 addition & 1 deletion src/client/mac/handler/dynamic_images.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DynamicImage {
DynamicImage(uint8_t* header, // data is copied
size_t header_size, // includes load commands
uint64_t load_address,
string file_path,
const string& file_path,
uintptr_t image_mod_date,
mach_port_t task,
cpu_type_t cpu_type)
Expand Down
2 changes: 1 addition & 1 deletion src/common/linux/dump_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ class LoadSymbolsInfo {
string debuglink_file() const {
return debuglink_file_;
}
void set_debuglink_file(string file) {
void set_debuglink_file(const string& file) {
debuglink_file_ = file;
}

Expand Down
2 changes: 1 addition & 1 deletion src/processor/basic_source_line_resolver_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ using google_breakpad::SymbolParseHelper;

class TestCodeModule : public CodeModule {
public:
TestCodeModule(string code_file) : code_file_(code_file) {}
TestCodeModule(const string& code_file) : code_file_(code_file) {}
virtual ~TestCodeModule() {}

virtual uint64_t base_address() const { return 0; }
Expand Down
20 changes: 13 additions & 7 deletions src/processor/disassembler_objdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ bool IsOperandSize(const string& token) {
return false;
}

bool GetSegmentAddressX86(const DumpContext& context, string segment_name,
bool GetSegmentAddressX86(const DumpContext& context,
const string& segment_name,
uint64_t& address) {
if (segment_name == "ds") {
address = context.GetContextX86()->ds;
Expand All @@ -91,7 +92,8 @@ bool GetSegmentAddressX86(const DumpContext& context, string segment_name,
return true;
}

bool GetSegmentAddressAMD64(const DumpContext& context, string segment_name,
bool GetSegmentAddressAMD64(const DumpContext& context,
const string& segment_name,
uint64_t& address) {
if (segment_name == "ds") {
address = 0;
Expand All @@ -105,7 +107,8 @@ bool GetSegmentAddressAMD64(const DumpContext& context, string segment_name,
return true;
}

bool GetSegmentAddress(const DumpContext& context, string segment_name,
bool GetSegmentAddress(const DumpContext& context,
const string& segment_name,
uint64_t& address) {
if (context.GetContextCPU() == MD_CONTEXT_X86) {
return GetSegmentAddressX86(context, segment_name, address);
Expand All @@ -117,7 +120,8 @@ bool GetSegmentAddress(const DumpContext& context, string segment_name,
}
}

bool GetRegisterValueX86(const DumpContext& context, string register_name,
bool GetRegisterValueX86(const DumpContext& context,
const string& register_name,
uint64_t& value) {
if (register_name == "eax") {
value = context.GetContextX86()->eax;
Expand Down Expand Up @@ -145,7 +149,8 @@ bool GetRegisterValueX86(const DumpContext& context, string register_name,
return true;
}

bool GetRegisterValueAMD64(const DumpContext& context, string register_name,
bool GetRegisterValueAMD64(const DumpContext& context,
const string& register_name,
uint64_t& value) {
if (register_name == "rax") {
value = context.GetContextAMD64()->rax;
Expand Down Expand Up @@ -193,7 +198,8 @@ bool GetRegisterValueAMD64(const DumpContext& context, string register_name,
// success.
// Support for non-full-size registers not implemented, since we're only using
// this to evaluate address expressions.
bool GetRegisterValue(const DumpContext& context, string register_name,
bool GetRegisterValue(const DumpContext& context,
const string& register_name,
uint64_t& value) {
if (context.GetContextCPU() == MD_CONTEXT_X86) {
return GetRegisterValueX86(context, register_name, value);
Expand Down Expand Up @@ -484,4 +490,4 @@ bool DisassemblerObjdump::CalculateDestAddress(const DumpContext& context,
return CalculateAddress(context, dest_, address);
}

} // namespace google_breakpad
} // namespace google_breakpad
2 changes: 1 addition & 1 deletion src/processor/fast_source_line_resolver_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ using google_breakpad::scoped_ptr;

class TestCodeModule : public CodeModule {
public:
explicit TestCodeModule(string code_file) : code_file_(code_file) {}
explicit TestCodeModule(const string& code_file) : code_file_(code_file) {}
virtual ~TestCodeModule() {}

virtual uint64_t base_address() const { return 0; }
Expand Down
4 changes: 2 additions & 2 deletions src/processor/windows_frame_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct WindowsFrameInfo {
uint32_t set_local_size,
uint32_t set_max_stack_size,
int set_allocates_base_pointer,
const string set_program_string)
const string& set_program_string)
: type_(type),
valid(VALID_ALL),
prolog_size(set_prolog_size),
Expand All @@ -111,7 +111,7 @@ struct WindowsFrameInfo {
// a string. Returns NULL if parsing fails, or a new object
// otherwise. type, rva and code_size are present in the STACK line,
// but not the StackFrameInfo structure, so return them as outparams.
static WindowsFrameInfo *ParseFromString(const string string,
static WindowsFrameInfo *ParseFromString(const string& string,
int& type,
uint64_t& rva,
uint64_t& code_size) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/windows/converter_exe/converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ static void ConvertMissingSymbolFile(const MissingSymbolInfo& missing_info,

// Reads the contents of file |file_name| and populates |contents|.
// Returns true on success.
static bool ReadFile(string file_name, string* contents) {
static bool ReadFile(const string& file_name, string* contents) {
char buffer[1024 * 8];
FILE* fp = fopen(file_name.c_str(), "rt");
if (!fp) {
Expand Down

0 comments on commit feea0f7

Please sign in to comment.