[Lldb-commits] [lldb] r349972 - [NFC] Replace `compare` with (in)equality operator where applicable.
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 21 14:46:10 PST 2018
Author: jdevlieghere
Date: Fri Dec 21 14:46:10 2018
New Revision: 349972
URL: http://llvm.org/viewvc/llvm-project?rev=349972&view=rev
Log:
[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.
Modified:
lldb/trunk/source/Core/IOHandler.cpp
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Host/common/XML.cpp
lldb/trunk/source/Interpreter/CommandAlias.cpp
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Symbol/ClangASTContext.cpp
lldb/trunk/source/Symbol/TypeList.cpp
lldb/trunk/source/Symbol/TypeMap.cpp
lldb/trunk/tools/debugserver/source/RNBRemote.cpp
lldb/trunk/tools/lldb-mi/MICmdArgValConsume.cpp
lldb/trunk/tools/lldb-mi/MIDriver.cpp
lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp
Modified: lldb/trunk/source/Core/IOHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/IOHandler.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Core/IOHandler.cpp (original)
+++ lldb/trunk/source/Core/IOHandler.cpp Fri Dec 21 14:46:10 2018
@@ -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();
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Dec 21 14:46:10 2018
@@ -783,7 +783,7 @@ void Module::LookupInfo::Prune(SymbolCon
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;
}
Modified: lldb/trunk/source/Host/common/XML.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/XML.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/XML.cpp (original)
+++ lldb/trunk/source/Host/common/XML.cpp Fri Dec 21 14:46:10 2018
@@ -438,7 +438,7 @@ XMLNode ApplePropertyList::GetValueNode(
"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();
Modified: lldb/trunk/source/Interpreter/CommandAlias.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandAlias.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandAlias.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandAlias.cpp Fri Dec 21 14:46:10 2018
@@ -158,8 +158,7 @@ void CommandAlias::GetAliasExpansion(Str
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());
}
}
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Fri Dec 21 14:46:10 2018
@@ -1393,7 +1393,7 @@ CommandObject *CommandInterpreter::Build
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::BuildAliasComma
// 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());
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp Fri Dec 21 14:46:10 2018
@@ -710,8 +710,7 @@ Status PlatformDarwinKernel::GetSharedMo
}
}
- 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)) {
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp Fri Dec 21 14:46:10 2018
@@ -256,7 +256,7 @@ PlatformMacOSX::GetFileWithUUID(const ll
#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();
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Dec 21 14:46:10 2018
@@ -1882,7 +1882,7 @@ ThreadSP ProcessGDBRemote::SetThreadStop
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::SetThreadStop
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::SetThreadStop
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::SetThreadStop
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));
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Dec 21 14:46:10 2018
@@ -7452,7 +7452,7 @@ ClangASTContext::GetIndexOfChildWithName
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;
}
Modified: lldb/trunk/source/Symbol/TypeList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeList.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeList.cpp (original)
+++ lldb/trunk/source/Symbol/TypeList.cpp Fri Dec 21 14:46:10 2018
@@ -180,8 +180,7 @@ void TypeList::RemoveMismatchedTypes(con
} 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;
}
}
Modified: lldb/trunk/source/Symbol/TypeMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeMap.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/TypeMap.cpp (original)
+++ lldb/trunk/source/Symbol/TypeMap.cpp Fri Dec 21 14:46:10 2018
@@ -223,8 +223,7 @@ void TypeMap::RemoveMismatchedTypes(cons
} 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;
}
}
Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Fri Dec 21 14:46:10 2018
@@ -1825,18 +1825,18 @@ rnb_err_t RNBRemote::HandlePacket_qRcmd(
}
if (*c == '\0') {
std::string command = get_identifier(line);
- if (command.compare("set") == 0) {
+ if (command == "set") {
std::string variable = get_identifier(line);
std::string op = get_operator(line);
std::string value = get_value(line);
- if (variable.compare("logfile") == 0) {
+ if (variable == "logfile") {
FILE *log_file = fopen(value.c_str(), "w");
if (log_file) {
DNBLogSetLogCallback(FileLogCallback, log_file);
return SendPacket("OK");
}
return SendPacket("E71");
- } else if (variable.compare("logmask") == 0) {
+ } else if (variable == "logmask") {
char *end;
errno = 0;
uint32_t logmask =
@@ -4231,7 +4231,7 @@ rnb_err_t RNBRemote::HandlePacket_GetPro
std::string name;
std::string value;
while (packet.GetNameColonValue(name, value)) {
- if (name.compare("scan_type") == 0) {
+ if (name == "scan_type") {
std::istringstream iss(value);
uint32_t int_value = 0;
if (iss >> std::hex >> int_value) {
@@ -4261,11 +4261,11 @@ rnb_err_t RNBRemote::HandlePacket_SetEna
std::string name;
std::string value;
while (packet.GetNameColonValue(name, value)) {
- if (name.compare("enable") == 0) {
+ if (name == "enable") {
enable = strtoul(value.c_str(), NULL, 10) > 0;
- } else if (name.compare("interval_usec") == 0) {
+ } else if (name == "interval_usec") {
interval_usec = strtoul(value.c_str(), NULL, 10);
- } else if (name.compare("scan_type") == 0) {
+ } else if (name == "scan_type") {
std::istringstream iss(value);
uint32_t int_value = 0;
if (iss >> std::hex >> int_value) {
Modified: lldb/trunk/tools/lldb-mi/MICmdArgValConsume.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdArgValConsume.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdArgValConsume.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdArgValConsume.cpp Fri Dec 21 14:46:10 2018
@@ -67,7 +67,7 @@ bool CMICmdArgValConsume::Validate(CMICm
while (it != vecOptions.end()) {
const CMIUtilString &rTxt(*it);
- if (rTxt.compare("--") == 0) {
+ if (rTxt == "--") {
m_bFound = true;
m_bValid = true;
if (!vwArgContext.RemoveArg(rTxt))
Modified: lldb/trunk/tools/lldb-mi/MIDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriver.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriver.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriver.cpp Fri Dec 21 14:46:10 2018
@@ -443,8 +443,7 @@ lldb::SBError CMIDriver::ParseArgs(const
CMICmdArgValString(true, false, true).IsStringArg(strArg)) {
// Is this the command file for the '-s' or '--source' options?
const CMIUtilString strPrevArg(argv[i - 1]);
- if (strPrevArg.compare("-s") == 0 ||
- strPrevArg.compare("--source") == 0) {
+ if (strPrevArg == "-s" || strPrevArg == "--source") {
m_strCmdLineArgCommandFileNamePath = strArg;
m_bHaveCommandFileNamePathOnCmdLine = true;
i--; // skip '-s' on the next loop
@@ -457,7 +456,7 @@ lldb::SBError CMIDriver::ParseArgs(const
}
// Report error if no command file was specified for the '-s' or
// '--source' options
- else if (strArg.compare("-s") == 0 || strArg.compare("--source") == 0) {
+ else if (strArg == "-s" || strArg == "--source") {
vwbExiting = true;
const CMIUtilString errMsg = CMIUtilString::Format(
MIRSRC(IDS_CMD_ARGS_ERR_VALIDATION_MISSING_INF), strArg.c_str());
@@ -465,13 +464,13 @@ lldb::SBError CMIDriver::ParseArgs(const
break;
}
// This argument is also checked for in CMIDriverMgr::ParseArgs()
- else if (strArg.compare("--executable") == 0) // Used to specify that
- // there is executable
- // argument also on the
- // command line
- { // See fn description.
+ else if (strArg == "--executable") // Used to specify that
+ // there is executable
+ // argument also on the
+ // command line
+ { // See fn description.
bHaveExecutableLongOption = true;
- } else if (strArg.compare("--synchronous") == 0) {
+ } else if (strArg == "--synchronous") {
CMICmnLLDBDebugSessionInfo::Instance().GetDebugger().SetAsync(false);
}
}
Modified: lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp?rev=349972&r1=349971&r2=349972&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MIDriverMgr.cpp Fri Dec 21 14:46:10 2018
@@ -516,29 +516,27 @@ bool CMIDriverMgr::ParseArgs(const int a
const CMIUtilString strArg(argv[i]);
// Argument "--executable" is also check for in CMIDriver::ParseArgs()
- if ((0 ==
- strArg.compare(
- "--interpreter")) || // Given by the client such as Eclipse
- (0 == strArg.compare("--executable"))) // Used to specify that there
- // is executable argument also
- // on the command line
- { // See fn description.
+ if (("--interpreter" == strArg) || // Given by the client such as Eclipse
+ ("--executable" == strArg)) // Used to specify that there
+ // is executable argument also
+ // on the command line
+ { // See fn description.
bHaveArgInterpret = true;
}
- if (0 == strArg.compare("--version")) {
+ if ("--version" == strArg) {
bHaveArgVersion = true;
}
- if (0 == strArg.compare("--versionLong")) {
+ if ("--versionLong" == strArg) {
bHaveArgVersionLong = true;
}
- if (0 == strArg.compare("--log")) {
+ if ("--log" == strArg) {
bHaveArgLog = true;
}
if (0 == strArg.compare(0, 10, "--log-dir=")) {
strLogDir = strArg.substr(10, CMIUtilString::npos);
bHaveArgLogDir = true;
}
- if ((0 == strArg.compare("--help")) || (0 == strArg.compare("-h"))) {
+ if (("--help" == strArg) || ("-h" == strArg)) {
bHaveArgHelp = true;
}
}
More information about the lldb-commits
mailing list