mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge #7907: Optimize and Cleanup CScript::FindAndDelete
d1d7775Improve worst-case behavior of CScript::FindAndDelete (Patrick Strateman)e2a30bcUnit test for CScript::FindAndDelete (Gavin Andresen)c0f660cReplace c-style cast with c++ style static_cast. (Patrick Strateman)ec9ad5fReplace memcmp with std::equal in CScript::FindAndDelete (Patrick Strateman)
This commit is contained in:
@@ -573,17 +573,26 @@ public:
|
||||
int nFound = 0;
|
||||
if (b.empty())
|
||||
return nFound;
|
||||
iterator pc = begin();
|
||||
CScript result;
|
||||
iterator pc = begin(), pc2 = begin();
|
||||
opcodetype opcode;
|
||||
do
|
||||
{
|
||||
while (end() - pc >= (long)b.size() && memcmp(&pc[0], &b[0], b.size()) == 0)
|
||||
result.insert(result.end(), pc2, pc);
|
||||
while (static_cast<size_t>(end() - pc) >= b.size() && std::equal(b.begin(), b.end(), pc))
|
||||
{
|
||||
pc = erase(pc, pc + b.size());
|
||||
pc = pc + b.size();
|
||||
++nFound;
|
||||
}
|
||||
pc2 = pc;
|
||||
}
|
||||
while (GetOp(pc, opcode));
|
||||
|
||||
if (nFound > 0) {
|
||||
result.insert(result.end(), pc2, end());
|
||||
*this = result;
|
||||
}
|
||||
|
||||
return nFound;
|
||||
}
|
||||
int Find(opcodetype op) const
|
||||
|
||||
Reference in New Issue
Block a user