1 /* -*- Mode: C++ -*- */
CmpDifferentBlockBytes(const Block & a,const Block & b)2 static size_t CmpDifferentBlockBytes(const Block &a, const Block &b) {
3 size_t total = 0;
4 size_t i = 0;
5 size_t m = min(a.Size(), b.Size());
6
7 for (; i < m; i++) {
8 if (a[i] != b[i]) {
9 total++;
10 }
11 }
12
13 total += a.Size() - i;
14 total += b.Size() - i;
15
16 return total;
17 }
18
CmpDifferentBytes(const FileSpec & a,const FileSpec & b)19 static xoff_t CmpDifferentBytes(const FileSpec &a, const FileSpec &b) {
20 Block block_a, block_b;
21 xoff_t total = 0;
22 typename FileSpec::iterator a_i(a), b_i(b);
23
24 for (; !a_i.Done() && !b_i.Done(); a_i.Next(), b_i.Next()) {
25
26 a_i.Get(&block_a);
27 b_i.Get(&block_b);
28
29 total += CmpDifferentBlockBytes(block_a, block_b);
30 }
31
32 for (; !a_i.Done(); a_i.Next()) {
33 total += a_i.BytesOnBlock();
34 }
35 for (; !b_i.Done(); b_i.Next()) {
36 total += b_i.BytesOnBlock();
37 }
38
39 return total;
40 }
41
CmpDifferentBlockBytesAtOffset(const Block & a,const FileSpec & b_spec,xoff_t offset)42 static size_t CmpDifferentBlockBytesAtOffset(const Block &a,
43 const FileSpec &b_spec,
44 xoff_t offset) {
45 Block b;
46 size_t size = a.Size();
47 CHECK_LE(offset, b_spec.Size());
48 if (b_spec.Size() < offset + size) {
49 size = b_spec.Size() - offset;
50 }
51 b_spec.Get(&b, offset, size);
52 return CmpDifferentBlockBytes(a, b);
53 }
54