On 03/29/2014 09:12 AM, 陈梁 wrote: > /* word at a time for speed */ > if (!res) { > while (i < slen && > (*(long *)(old_buf + i)) == (*(long *)(new_buf + i))) { > i += sizeof(long); > zrun_len += sizeof(long); > } > > /* go over the rest */ > //while (i < slen && old_buf[i] == new_buf[i]) { > // zrun_len++; > // i++; > //} > } > i += sizeof(long); > nzrun_len += sizeof(long);
That does not produce a minimal compression (it treats all 8 bytes as different, even if 7 of them were the same). It might be a viable solution if the extra overhead of the additional bytes sent over the wire is less than the overhead saved by not re-checking the temporary variable to determine a better compression. But I'm not convinced - it seems that reading memory into a register, then doing multiple operations on that cached value, will be a win (that is, minimal compression matters, because time spent transmitting bytes over the network is slower than time spent calculating how to avoid bytes to transmit). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature