Skip to content

Commit

Permalink
[Bug][Memory][Performance] Optimize and Cleanup CScript::FindAndDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquid369 committed Jan 10, 2020
1 parent 82403b0 commit ccc7f97
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/script/script.h
Expand Up @@ -564,17 +564,24 @@ class CScript : public std::vector<unsigned char>
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
Expand Down

0 comments on commit ccc7f97

Please sign in to comment.