diff --git a/src/engine/cmdStreamOps.cpp b/src/engine/cmdStreamOps.cpp index 61bd8c35f..593be78c9 100644 --- a/src/engine/cmdStreamOps.cpp +++ b/src/engine/cmdStreamOps.cpp @@ -794,10 +794,41 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector& subBlock // search for small matches, and then find bigger ones logD("finding possible matches"); for (size_t i=0; isize(); i+=8) { + if ((i&8191)==0) logV("%d of %d",i,(int)stream->size()); for (size_t j=i+matchSize; jsize(); j+=8) { if (memcmp(&buf[i],&buf[j],matchSize)==0) { - // store this match for later - matches.push_back(BlockMatch(i,j,matchSize)); + BlockMatch b=BlockMatch(i,j,matchSize); + + // determine match size + size_t finalLen=b.len; + size_t origPos=b.orig+b.len; + size_t blockPos=b.block+b.len; + while (true) { + if (origPos>=stream->size() || blockPos>=stream->size()) { + break; + } + + if (buf[origPos]!=buf[blockPos]) { + break; + } + origPos++; + blockPos++; + finalLen++; + } + + finalLen&=~7; + b.len=finalLen; + b.done=true; + + // if this match is bigger than the match size, change the match size + // we're only going to work on the largest matches anyway + if (finalLen>matchSize) { + logW("expand dong"); + matchSize=finalLen; + } + + // store this match + matches.push_back(b); } } } @@ -807,35 +838,6 @@ SafeWriter* findSubBlocks(SafeWriter* stream, std::vector& subBlock // quit if there isn't anything if (matches.empty()) return stream; - // search for bigger matches - for (size_t i=0; i=stream->size() || blockPos>=stream->size()) { - break; - } - - if (buf[origPos]!=buf[blockPos]) { - break; - } - origPos++; - blockPos++; - finalLen++; - } - - finalLen&=~7; - b.len=finalLen; - b.done=true; - } - logD("checking overlapping/bad matches"); // first stage done