aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2016-04-19 13:17:38 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2016-04-21 17:24:36 -0700
commitd1d7775587473410a107e7079616b9ecaae8dd06 (patch)
tree42dcaaf256a923127fc7d13dfa396c97a15d00ca /src/script
parente2a30bc9a9f7d2969e52632f8e8942a4e72f4ba6 (diff)
Improve worst-case behavior of CScript::FindAndDelete
Thanks to Sergio Lerner for identifying this issue and suggesting this kind of solution.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/script/script.h b/src/script/script.h
index 0503b39a76..bdbd340bcc 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -570,17 +570,26 @@ public:
int nFound = 0;
if (b.empty())
return nFound;
- iterator pc = begin();
+ CScript result;
+ iterator pc = begin(), pc2 = begin();
opcodetype opcode;
do
{
+ 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