Skip to content

Commit

Permalink
Merge #12159: Use the character based overload for std::string::find.
Browse files Browse the repository at this point in the history
Summary:
a73aab7 Use the character based overload for std::string::find. (Alin Rus)

Pull request description:

  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.

Tree-SHA512: dc7684b1551e6d779eb989e9a74363f9b978059a7c0f3db09d01744c7e6452961f9e671173265e71efff27afbcb80c0fe2c11b6dff2290e54a49193fa25a5679

Backport of Core PR12159
bitcoin/bitcoin#12159

Test Plan:
  make check

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3750
  • Loading branch information
laanwj authored and jonspock committed Dec 22, 2019
1 parent b2dc2c2 commit 6a7187f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static void MutateTxAddOutPubKey(CMutableTransaction &tx,
bool bScriptHash = false;
if (vStrInputParts.size() == 3) {
std::string flags = vStrInputParts[2];
bScriptHash = (flags.find("S") != std::string::npos);
bScriptHash = (flags.find('S') != std::string::npos);
}

if (bScriptHash) {
Expand Down Expand Up @@ -394,7 +394,7 @@ static void MutateTxAddOutMultiSig(CMutableTransaction &tx,
bool bScriptHash = false;
if (vStrInputParts.size() == numkeys + 4) {
std::string flags = vStrInputParts.back();
bScriptHash = (flags.find("S") != std::string::npos);
bScriptHash = (flags.find('S') != std::string::npos);
} else if (vStrInputParts.size() > numkeys + 4) {
// Validate that there were no more parameters passed
throw std::runtime_error("Too many parameters");
Expand Down Expand Up @@ -461,7 +461,7 @@ static void MutateTxAddOutScript(CMutableTransaction &tx,
bool bScriptHash = false;
if (vStrInputParts.size() == 3) {
std::string flags = vStrInputParts.back();
bScriptHash = (flags.find("S") != std::string::npos);
bScriptHash = (flags.find('S') != std::string::npos);
}

if (bScriptHash) {
Expand Down
10 changes: 5 additions & 5 deletions src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ static void JSONErrorReply(HTTPRequest *req, const UniValue &objError,
* 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
Expand Down Expand Up @@ -147,8 +147,8 @@ static bool RPCAuthorized(Config &config, const std::string &strAuth,
rtrim(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
Expand Down
4 changes: 2 additions & 2 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ static bool rest_getutxos(Config &config, HTTPRequest *req,

for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++) {
int32_t nOutput;
std::string strTxid = uriParts[i].substr(0, uriParts[i].find("-"));
std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
std::string strOutput =
uriParts[i].substr(uriParts[i].find("-") + 1);
uriParts[i].substr(uriParts[i].find('-') + 1);

if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid)) {
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ UniValue RPCConvertNamedValues(const std::string &strMethod,
UniValue params(UniValue::VOBJ);

for (const std::string &s : strParams) {
size_t pos = s.find("=");
size_t pos = s.find('=');
if (pos == std::string::npos) {
throw(std::runtime_error("No '=' in named argument '" + s +
"', this needs to be present for every "
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ static UniValue setban(const Config &config, const JSONRPCRequest &request) {
CNetAddr netAddr;
bool isSubnet = false;

if (request.params[0].get_str().find("/") != std::string::npos) {
if (request.params[0].get_str().find('/') != std::string::npos) {
isSubnet = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ class CAccountingEntry {
s >> nCreditDebit >> nTime >> LIMITED_STRING(strOtherAccount, 65536) >>
LIMITED_STRING(strComment, 65536);

size_t nSepPos = strComment.find("\0", 0, 1);
size_t nSepPos = strComment.find('\0');
mapValue.clear();
if (std::string::npos != nSepPos) {
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1,
Expand Down

0 comments on commit 6a7187f

Please sign in to comment.