clang-tidy: Add performance-faster-string-find check

https://clang.llvm.org/extra/clang-tidy/checks/performance/faster-string-find.html
This commit is contained in:
Hennadii Stepanov
2023-03-26 20:17:46 +01:00
parent 483fb8d216
commit 516b75f66e
4 changed files with 5 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ bugprone-use-after-move,
misc-unused-using-decls, misc-unused-using-decls,
modernize-use-default-member-init, modernize-use-default-member-init,
modernize-use-nullptr, modernize-use-nullptr,
performance-faster-string-find,
performance-for-range-copy, performance-for-range-copy,
performance-move-const-arg, performance-move-const-arg,
performance-no-automatic-move, performance-no-automatic-move,

View File

@@ -732,12 +732,12 @@ UniValue RPCArg::MatchesType(const UniValue& request) const
std::string RPCArg::GetFirstName() const std::string RPCArg::GetFirstName() const
{ {
return m_names.substr(0, m_names.find("|")); return m_names.substr(0, m_names.find('|'));
} }
std::string RPCArg::GetName() const std::string RPCArg::GetName() const
{ {
CHECK_NONFATAL(std::string::npos == m_names.find("|")); CHECK_NONFATAL(std::string::npos == m_names.find('|'));
return m_names; return m_names;
} }

View File

@@ -25,7 +25,7 @@ bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypa
} }
// Finds whether it is hardened // Finds whether it is hardened
uint32_t path = 0; uint32_t path = 0;
size_t pos = item.find("'"); size_t pos = item.find('\'');
if (pos != std::string::npos) { if (pos != std::string::npos) {
// The hardened tick can only be in the last index of the string // The hardened tick can only be in the last index of the string
if (pos != item.size() - 1) { if (pos != item.size() - 1) {

View File

@@ -96,7 +96,7 @@ static bool IsZMQAddressIPV6(const std::string &zmq_address)
{ {
const std::string tcp_prefix = "tcp://"; const std::string tcp_prefix = "tcp://";
const size_t tcp_index = zmq_address.rfind(tcp_prefix); const size_t tcp_index = zmq_address.rfind(tcp_prefix);
const size_t colon_index = zmq_address.rfind(":"); const size_t colon_index = zmq_address.rfind(':');
if (tcp_index == 0 && colon_index != std::string::npos) { if (tcp_index == 0 && colon_index != std::string::npos) {
const std::string ip = zmq_address.substr(tcp_prefix.length(), colon_index - tcp_prefix.length()); const std::string ip = zmq_address.substr(tcp_prefix.length(), colon_index - tcp_prefix.length());
CNetAddr addr; CNetAddr addr;