diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-12-21 22:46:10 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-12-21 22:46:10 +0000 |
commit | 8bb1c06ab3b46b1f95d5a946789b8edac8007403 (patch) | |
tree | 115249f4eef87bfbbfe45e40599538fe379fecf8 /lldb/tools | |
parent | b61673d63b5e0e6bbe3f8463c33286f17f7d85b8 (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/tools')
-rw-r--r-- | lldb/tools/debugserver/source/RNBRemote.cpp | 14 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MICmdArgValConsume.cpp | 2 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MIDriver.cpp | 17 | ||||
-rw-r--r-- | lldb/tools/lldb-mi/MIDriverMgr.cpp | 20 |
4 files changed, 25 insertions, 28 deletions
diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp index 7c5bba4484e..f611ec0d219 100644 --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -1825,18 +1825,18 @@ rnb_err_t RNBRemote::HandlePacket_qRcmd(const char *p) { } 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_GetProfileData(const char *p) { 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_SetEnableAsyncProfiling(const char *p) { 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) { diff --git a/lldb/tools/lldb-mi/MICmdArgValConsume.cpp b/lldb/tools/lldb-mi/MICmdArgValConsume.cpp index 5a76ab4b56f..86c4f091256 100644 --- a/lldb/tools/lldb-mi/MICmdArgValConsume.cpp +++ b/lldb/tools/lldb-mi/MICmdArgValConsume.cpp @@ -67,7 +67,7 @@ bool CMICmdArgValConsume::Validate(CMICmdArgContext &vwArgContext) { while (it != vecOptions.end()) { const CMIUtilString &rTxt(*it); - if (rTxt.compare("--") == 0) { + if (rTxt == "--") { m_bFound = true; m_bValid = true; if (!vwArgContext.RemoveArg(rTxt)) diff --git a/lldb/tools/lldb-mi/MIDriver.cpp b/lldb/tools/lldb-mi/MIDriver.cpp index 23039110b42..cb8fb1c2c25 100644 --- a/lldb/tools/lldb-mi/MIDriver.cpp +++ b/lldb/tools/lldb-mi/MIDriver.cpp @@ -443,8 +443,7 @@ lldb::SBError CMIDriver::ParseArgs(const int argc, const char *argv[], 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 int argc, const char *argv[], } // 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 int argc, const char *argv[], 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); } } diff --git a/lldb/tools/lldb-mi/MIDriverMgr.cpp b/lldb/tools/lldb-mi/MIDriverMgr.cpp index 6b39832d736..93070a5912d 100644 --- a/lldb/tools/lldb-mi/MIDriverMgr.cpp +++ b/lldb/tools/lldb-mi/MIDriverMgr.cpp @@ -516,29 +516,27 @@ bool CMIDriverMgr::ParseArgs(const int argc, const char *argv[], 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; } } |