From a73aab7cd8343d795b1a7408bd71f522262ac76e Mon Sep 17 00:00:00 2001 From: Alin Rus Date: Thu, 11 Jan 2018 21:40:51 +0100 Subject: [PATCH] Use the character based overload for std::string::find. std::string::find has a character based overload as can be seen here (4th oveload): http://www.cplusplus.com/reference/string/string/find/ Use that instead of constantly allocating temporary strings. --- src/bitcoin-tx.cpp | 12 ++++++------ src/httprpc.cpp | 10 +++++----- src/rest.cpp | 4 ++-- src/rpc/client.cpp | 2 +- src/rpc/net.cpp | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 9bcf3fe8d..f1cf7c9d2 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -305,8 +305,8 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str bool bScriptHash = false; if (vStrInputParts.size() == 3) { std::string flags = vStrInputParts[2]; - bSegWit = (flags.find("W") != std::string::npos); - bScriptHash = (flags.find("S") != std::string::npos); + bSegWit = (flags.find('W') != std::string::npos); + bScriptHash = (flags.find('S') != std::string::npos); } if (bSegWit) { @@ -367,8 +367,8 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s bool bScriptHash = false; if (vStrInputParts.size() == numkeys + 4) { std::string flags = vStrInputParts.back(); - bSegWit = (flags.find("W") != std::string::npos); - bScriptHash = (flags.find("S") != std::string::npos); + bSegWit = (flags.find('W') != std::string::npos); + bScriptHash = (flags.find('S') != std::string::npos); } else if (vStrInputParts.size() > numkeys + 4) { // Validate that there were no more parameters passed @@ -447,8 +447,8 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str bool bScriptHash = false; if (vStrInputParts.size() == 3) { std::string flags = vStrInputParts.back(); - bSegWit = (flags.find("W") != std::string::npos); - bScriptHash = (flags.find("S") != std::string::npos); + bSegWit = (flags.find('W') != std::string::npos); + bScriptHash = (flags.find('S') != std::string::npos); } if (scriptPubKey.size() > MAX_SCRIPT_SIZE) { diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 66f7a6a71..5e9e41974 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -85,11 +85,11 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni //entries from config file. static bool multiUserAuthorized(std::string strUserPass) { - if (strUserPass.find(":") == std::string::npos) { + if (strUserPass.find(':') == std::string::npos) { return false; } - std::string strUser = strUserPass.substr(0, strUserPass.find(":")); - std::string strPass = strUserPass.substr(strUserPass.find(":") + 1); + std::string strUser = strUserPass.substr(0, strUserPass.find(':')); + std::string strPass = strUserPass.substr(strUserPass.find(':') + 1); for (const std::string& strRPCAuth : gArgs.GetArgs("-rpcauth")) { //Search for multi-user login/pass "rpcauth" from config @@ -132,8 +132,8 @@ static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUserna boost::trim(strUserPass64); std::string strUserPass = DecodeBase64(strUserPass64); - if (strUserPass.find(":") != std::string::npos) - strAuthUsernameOut = strUserPass.substr(0, strUserPass.find(":")); + if (strUserPass.find(':') != std::string::npos) + strAuthUsernameOut = strUserPass.substr(0, strUserPass.find(':')); //Check if authorized under single-user field if (TimingResistantEqual(strUserPass, strRPCUserColonPass)) { diff --git a/src/rest.cpp b/src/rest.cpp index 0c93ce020..30e481171 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -423,8 +423,8 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) { uint256 txid; int32_t nOutput; - std::string strTxid = uriParts[i].substr(0, uriParts[i].find("-")); - std::string strOutput = uriParts[i].substr(uriParts[i].find("-")+1); + std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-')); + std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1); if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid)) return RESTERR(req, HTTP_BAD_REQUEST, "Parse error"); diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index f63e970bd..b88c1bccd 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -213,7 +213,7 @@ UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector