summaryrefslogtreecommitdiff
path: root/bsdiff.cc
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2018-04-06 15:33:06 -0700
committerSen Jiang <senj@google.com>2018-04-09 17:32:51 -0700
commit3a4725a87796a3dec4c81501daef1eebf4d5ed88 (patch)
tree11da834207f4550a175063219e58c52ac89829e9 /bsdiff.cc
parenta65e5485c955499ec98cb052f7b1b00693dadae8 (diff)
downloadbsdiff-3a4725a87796a3dec4c81501daef1eebf4d5ed88.tar.gz
Exit loop ealier when matching lastoffset.
|lastoffset| and |oldsize| doesn't change in this loop, no point keep incrementing |scsc| and comparing. bsdiff is about 2% faster with no change on the patch content. Bug: 77817425 Test: bsdiff_unittest Change-Id: Ie6a5ddc4b8805ed76c9c626fa75010617b7975ef
Diffstat (limited to 'bsdiff.cc')
-rw-r--r--bsdiff.cc7
1 files changed, 3 insertions, 4 deletions
diff --git a/bsdiff.cc b/bsdiff.cc
index c775bdf..8bb21b7 100644
--- a/bsdiff.cc
+++ b/bsdiff.cc
@@ -114,10 +114,9 @@ int bsdiff(const uint8_t* old_buf, size_t oldsize, const uint8_t* new_buf,
sai->SearchPrefix(new_buf + scan, newsize - scan, &len, &pos);
- for(;scsc<scan+len;scsc++)
- if((scsc+lastoffset<oldsize) &&
- (old_buf[scsc+lastoffset] == new_buf[scsc]))
- oldscore++;
+ for(;scsc<scan+len && scsc+lastoffset<oldsize;scsc++)
+ if(old_buf[scsc+lastoffset] == new_buf[scsc])
+ oldscore++;
if(((len==oldscore) && (len!=0)) ||
(len>oldscore+8 && len>=min_length)) break;