Skip to content

Commit a73aab7

Browse files
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.
1 parent 1d2eaba commit a73aab7

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/bitcoin-tx.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
305305
bool bScriptHash = false;
306306
if (vStrInputParts.size() == 3) {
307307
std::string flags = vStrInputParts[2];
308-
bSegWit = (flags.find("W") != std::string::npos);
309-
bScriptHash = (flags.find("S") != std::string::npos);
308+
bSegWit = (flags.find('W') != std::string::npos);
309+
bScriptHash = (flags.find('S') != std::string::npos);
310310
}
311311

312312
if (bSegWit) {
@@ -367,8 +367,8 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
367367
bool bScriptHash = false;
368368
if (vStrInputParts.size() == numkeys + 4) {
369369
std::string flags = vStrInputParts.back();
370-
bSegWit = (flags.find("W") != std::string::npos);
371-
bScriptHash = (flags.find("S") != std::string::npos);
370+
bSegWit = (flags.find('W') != std::string::npos);
371+
bScriptHash = (flags.find('S') != std::string::npos);
372372
}
373373
else if (vStrInputParts.size() > numkeys + 4) {
374374
// Validate that there were no more parameters passed
@@ -447,8 +447,8 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
447447
bool bScriptHash = false;
448448
if (vStrInputParts.size() == 3) {
449449
std::string flags = vStrInputParts.back();
450-
bSegWit = (flags.find("W") != std::string::npos);
451-
bScriptHash = (flags.find("S") != std::string::npos);
450+
bSegWit = (flags.find('W') != std::string::npos);
451+
bScriptHash = (flags.find('S') != std::string::npos);
452452
}
453453

454454
if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {

src/httprpc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni
8585
//entries from config file.
8686
static bool multiUserAuthorized(std::string strUserPass)
8787
{
88-
if (strUserPass.find(":") == std::string::npos) {
88+
if (strUserPass.find(':') == std::string::npos) {
8989
return false;
9090
}
91-
std::string strUser = strUserPass.substr(0, strUserPass.find(":"));
92-
std::string strPass = strUserPass.substr(strUserPass.find(":") + 1);
91+
std::string strUser = strUserPass.substr(0, strUserPass.find(':'));
92+
std::string strPass = strUserPass.substr(strUserPass.find(':') + 1);
9393

9494
for (const std::string& strRPCAuth : gArgs.GetArgs("-rpcauth")) {
9595
//Search for multi-user login/pass "rpcauth" from config
@@ -132,8 +132,8 @@ static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUserna
132132
boost::trim(strUserPass64);
133133
std::string strUserPass = DecodeBase64(strUserPass64);
134134

135-
if (strUserPass.find(":") != std::string::npos)
136-
strAuthUsernameOut = strUserPass.substr(0, strUserPass.find(":"));
135+
if (strUserPass.find(':') != std::string::npos)
136+
strAuthUsernameOut = strUserPass.substr(0, strUserPass.find(':'));
137137

138138
//Check if authorized under single-user field
139139
if (TimingResistantEqual(strUserPass, strRPCUserColonPass)) {

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart)
423423
{
424424
uint256 txid;
425425
int32_t nOutput;
426-
std::string strTxid = uriParts[i].substr(0, uriParts[i].find("-"));
427-
std::string strOutput = uriParts[i].substr(uriParts[i].find("-")+1);
426+
std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
427+
std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1);
428428

429429
if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
430430
return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");

src/rpc/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector<s
213213
UniValue params(UniValue::VOBJ);
214214

215215
for (const std::string &s: strParams) {
216-
size_t pos = s.find("=");
216+
size_t pos = s.find('=');
217217
if (pos == std::string::npos) {
218218
throw(std::runtime_error("No '=' in named argument '"+s+"', this needs to be present for every argument (even if it is empty)"));
219219
}

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ UniValue setban(const JSONRPCRequest& request)
516516
CNetAddr netAddr;
517517
bool isSubnet = false;
518518

519-
if (request.params[0].get_str().find("/") != std::string::npos)
519+
if (request.params[0].get_str().find('/') != std::string::npos)
520520
isSubnet = true;
521521

522522
if (!isSubnet) {

0 commit comments

Comments
 (0)