summaryrefslogtreecommitdiff
path: root/lldb/source
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2018-12-21 22:46:10 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2018-12-21 22:46:10 +0000
commit8bb1c06ab3b46b1f95d5a946789b8edac8007403 (patch)
tree115249f4eef87bfbbfe45e40599538fe379fecf8 /lldb/source
parentb61673d63b5e0e6bbe3f8463c33286f17f7d85b8 (diff)
[NFC] Replace `compare` with (in)equality operator where applicable.
Using compare is verbose, bug prone and potentially inefficient (because of early termination). Replace relevant call sites with the (in)equality operator.
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Core/IOHandler.cpp2
-rw-r--r--lldb/source/Core/Module.cpp2
-rw-r--r--lldb/source/Host/common/XML.cpp2
-rw-r--r--lldb/source/Interpreter/CommandAlias.cpp3
-rw-r--r--lldb/source/Interpreter/CommandInterpreter.cpp4
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp3
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp2
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp12
-rw-r--r--lldb/source/Symbol/ClangASTContext.cpp2
-rw-r--r--lldb/source/Symbol/TypeList.cpp3
-rw-r--r--lldb/source/Symbol/TypeMap.cpp3
11 files changed, 17 insertions, 21 deletions
diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp
index 682b7bb2e99..5c0eea5ea1a 100644
--- a/lldb/source/Core/IOHandler.cpp
+++ b/lldb/source/Core/IOHandler.cpp
@@ -1052,7 +1052,7 @@ public:
Windows::iterator pos, end = m_subwindows.end();
size_t i = 0;
for (pos = m_subwindows.begin(); pos != end; ++pos, ++i) {
- if ((*pos)->m_name.compare(name) == 0)
+ if ((*pos)->m_name == name)
return *pos;
}
return WindowSP();
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 76c898fc0cd..a53d54fb103 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -783,7 +783,7 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
qualified_name = cpp_method.GetBasename().str();
else
qualified_name = cpp_method.GetScopeQualifiedName();
- if (qualified_name.compare(m_name.GetCString()) != 0) {
+ if (qualified_name != m_name.GetCString()) {
sc_list.RemoveContextAtIndex(i);
continue;
}
diff --git a/lldb/source/Host/common/XML.cpp b/lldb/source/Host/common/XML.cpp
index b964a2e26fa..967a294cbf7 100644
--- a/lldb/source/Host/common/XML.cpp
+++ b/lldb/source/Host/common/XML.cpp
@@ -438,7 +438,7 @@ XMLNode ApplePropertyList::GetValueNode(const char *key) const {
"key", [key, &value_node](const XMLNode &key_node) -> bool {
std::string key_name;
if (key_node.GetElementText(key_name)) {
- if (key_name.compare(key) == 0) {
+ if (key_name == key) {
value_node = key_node.GetSibling();
while (value_node && !value_node.IsElement())
value_node = value_node.GetSibling();
diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp
index a4b0a0c55c0..078eb73a7a8 100644
--- a/lldb/source/Interpreter/CommandAlias.cpp
+++ b/lldb/source/Interpreter/CommandAlias.cpp
@@ -158,8 +158,7 @@ void CommandAlias::GetAliasExpansion(StreamString &help_string) const {
help_string.Printf(" %s", value.c_str());
} else {
help_string.Printf(" %s", opt.c_str());
- if ((value.compare("<no-argument>") != 0) &&
- (value.compare("<need-argument") != 0)) {
+ if ((value != "<no-argument>") && (value != "<need-argument")) {
help_string.Printf(" %s", value.c_str());
}
}
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 1072b444707..16a4a6220cb 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1393,7 +1393,7 @@ CommandObject *CommandInterpreter::BuildAliasResult(
alias_cmd_obj = desugared.first.get();
std::string alias_name_str = alias_name;
if ((cmd_args.GetArgumentCount() == 0) ||
- (alias_name_str.compare(cmd_args.GetArgumentAtIndex(0)) != 0))
+ (alias_name_str != cmd_args.GetArgumentAtIndex(0)))
cmd_args.Unshift(alias_name_str);
result_str.Printf("%s", alias_cmd_obj->GetCommandName().str().c_str());
@@ -1937,7 +1937,7 @@ void CommandInterpreter::BuildAliasCommandArgs(CommandObject *alias_cmd_obj,
// Make sure that the alias name is the 0th element in cmd_args
std::string alias_name_str = alias_name;
- if (alias_name_str.compare(cmd_args.GetArgumentAtIndex(0)) != 0)
+ if (alias_name_str != cmd_args.GetArgumentAtIndex(0))
cmd_args.Unshift(alias_name_str);
Args new_args(alias_cmd_obj->GetCommandName());
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
index 33078585002..221568bbdaf 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -710,8 +710,7 @@ Status PlatformDarwinKernel::GetSharedModule(
}
}
- if (kext_bundle_id.compare("mach_kernel") == 0 &&
- module_spec.GetUUID().IsValid()) {
+ if (kext_bundle_id == "mach_kernel" && module_spec.GetUUID().IsValid()) {
// First try all kernel binaries that have a dSYM next to them
for (auto possible_kernel : m_kernel_binaries_with_dsyms) {
if (FileSystem::Instance().Exists(possible_kernel)) {
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index 4e18b90f5d5..4117231c308 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -256,7 +256,7 @@ PlatformMacOSX::GetFileWithUUID(const lldb_private::FileSpec &platform_file,
#endif
std::string remote_os_build;
m_remote_platform_sp->GetOSBuildString(remote_os_build);
- if (local_os_build.compare(remote_os_build) == 0) {
+ if (local_os_build == remote_os_build) {
// same OS version: the local file is good enough
local_file = platform_file;
return Status();
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index ef0915f70c1..797f63d537a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1882,7 +1882,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
bool handled = false;
bool did_exec = false;
if (!reason.empty()) {
- if (reason.compare("trace") == 0) {
+ if (reason == "trace") {
addr_t pc = thread_sp->GetRegisterContext()->GetPC();
lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()
->GetBreakpointSiteList()
@@ -1900,7 +1900,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
thread_sp->SetStopInfo(
StopInfo::CreateStopReasonToTrace(*thread_sp));
handled = true;
- } else if (reason.compare("breakpoint") == 0) {
+ } else if (reason == "breakpoint") {
addr_t pc = thread_sp->GetRegisterContext()->GetPC();
lldb::BreakpointSiteSP bp_site_sp = thread_sp->GetProcess()
->GetBreakpointSiteList()
@@ -1921,9 +1921,9 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
thread_sp->SetStopInfo(invalid_stop_info_sp);
}
}
- } else if (reason.compare("trap") == 0) {
+ } else if (reason == "trap") {
// Let the trap just use the standard signal stop reason below...
- } else if (reason.compare("watchpoint") == 0) {
+ } else if (reason == "watchpoint") {
StringExtractor desc_extractor(description.c_str());
addr_t wp_addr = desc_extractor.GetU64(LLDB_INVALID_ADDRESS);
uint32_t wp_index = desc_extractor.GetU32(LLDB_INVALID_INDEX32);
@@ -1955,11 +1955,11 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
thread_sp->SetStopInfo(StopInfo::CreateStopReasonWithWatchpointID(
*thread_sp, watch_id, wp_hit_addr));
handled = true;
- } else if (reason.compare("exception") == 0) {
+ } else if (reason == "exception") {
thread_sp->SetStopInfo(StopInfo::CreateStopReasonWithException(
*thread_sp, description.c_str()));
handled = true;
- } else if (reason.compare("exec") == 0) {
+ } else if (reason == "exec") {
did_exec = true;
thread_sp->SetStopInfo(
StopInfo::CreateStopReasonWithExec(*thread_sp));
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 0fb4699ac35..5052f3c2a44 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -7452,7 +7452,7 @@ ClangASTContext::GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
base_class->getType());
std::string base_class_type_name(
base_class_clang_type.GetTypeName().AsCString(""));
- if (base_class_type_name.compare(name) == 0)
+ if (base_class_type_name == name)
return child_idx;
++child_idx;
}
diff --git a/lldb/source/Symbol/TypeList.cpp b/lldb/source/Symbol/TypeList.cpp
index f70982fd0d2..26a646e6469 100644
--- a/lldb/source/Symbol/TypeList.cpp
+++ b/lldb/source/Symbol/TypeList.cpp
@@ -180,8 +180,7 @@ void TypeList::RemoveMismatchedTypes(const std::string &type_scope,
} else {
// The type we are currently looking at doesn't exists in a namespace
// or class, so it only matches if there is no type scope...
- keep_match =
- type_scope.empty() && type_basename.compare(match_type_name) == 0;
+ keep_match = type_scope.empty() && type_basename == match_type_name;
}
}
diff --git a/lldb/source/Symbol/TypeMap.cpp b/lldb/source/Symbol/TypeMap.cpp
index 5bbf6d6908c..337278c202e 100644
--- a/lldb/source/Symbol/TypeMap.cpp
+++ b/lldb/source/Symbol/TypeMap.cpp
@@ -223,8 +223,7 @@ void TypeMap::RemoveMismatchedTypes(const std::string &type_scope,
} else {
// The type we are currently looking at doesn't exists in a namespace
// or class, so it only matches if there is no type scope...
- keep_match =
- type_scope.empty() && type_basename.compare(match_type_name) == 0;
+ keep_match = type_scope.empty() && type_basename == match_type_name;
}
}