aboutsummaryrefslogtreecommitdiff
path: root/src/script/script.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-05-05 19:00:42 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2016-05-05 19:01:32 +0200
commit006cdf64dc93239c05202b1a81d538ecda1e6c2a (patch)
tree7db894912ed5aad2294a4663230dd8af184b9365 /src/script/script.h
parent3b9a0bf41f2336b09e854522ab1ce6dcfc7a3050 (diff)
parentd1d7775587473410a107e7079616b9ecaae8dd06 (diff)
Merge #7907: Optimize and Cleanup CScript::FindAndDelete
d1d7775 Improve worst-case behavior of CScript::FindAndDelete (Patrick Strateman) e2a30bc Unit test for CScript::FindAndDelete (Gavin Andresen) c0f660c Replace c-style cast with c++ style static_cast. (Patrick Strateman) ec9ad5f Replace memcmp with std::equal in CScript::FindAndDelete (Patrick Strateman)
Diffstat (limited to 'src/script/script.h')
-rw-r--r--src/script/script.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/script/script.h b/src/script/script.h
index 2a338d6f5c..a2941ce901 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -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