mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
Improve worst-case behavior of CScript::FindAndDelete
Thanks to Sergio Lerner for identifying this issue and suggesting this kind of solution.
This commit is contained in:
parent
e2a30bc9a9
commit
d1d7775587
@ -570,17 +570,26 @@ public:
|
|||||||
int nFound = 0;
|
int nFound = 0;
|
||||||
if (b.empty())
|
if (b.empty())
|
||||||
return nFound;
|
return nFound;
|
||||||
iterator pc = begin();
|
CScript result;
|
||||||
|
iterator pc = begin(), pc2 = begin();
|
||||||
opcodetype opcode;
|
opcodetype opcode;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
result.insert(result.end(), pc2, pc);
|
||||||
while (static_cast<size_t>(end() - pc) >= b.size() && std::equal(b.begin(), b.end(), 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;
|
++nFound;
|
||||||
}
|
}
|
||||||
|
pc2 = pc;
|
||||||
}
|
}
|
||||||
while (GetOp(pc, opcode));
|
while (GetOp(pc, opcode));
|
||||||
|
|
||||||
|
if (nFound > 0) {
|
||||||
|
result.insert(result.end(), pc2, end());
|
||||||
|
*this = result;
|
||||||
|
}
|
||||||
|
|
||||||
return nFound;
|
return nFound;
|
||||||
}
|
}
|
||||||
int Find(opcodetype op) const
|
int Find(opcodetype op) const
|
||||||
|
Loading…
Reference in New Issue
Block a user