From: Eric Biggers Date: Sat, 6 Sep 2014 16:54:16 +0000 (-0500) Subject: lz_copy(): Unroll first iteration X-Git-Tag: v1.7.2~28 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=0158ecdaa9e7475a75799f369468f9af5a8ce4ea;hp=e02ea0a6b4aec8b3475ea24522f254affb6cfcd3 lz_copy(): Unroll first iteration Most matches are short, so 1 iteration is the most common case. Use separate branch for this. --- diff --git a/include/wimlib/decompress_common.h b/include/wimlib/decompress_common.h index da15fd1e..3f3742a0 100644 --- a/include/wimlib/decompress_common.h +++ b/include/wimlib/decompress_common.h @@ -277,13 +277,22 @@ lz_copy(u8 *dst, u32 length, u32 offset, const u8 *winend) unsigned long v; } _packed_attribute; - const u8 *end = dst + length; - do { - unsigned long v = ((struct ulong_wrapper *)src)->v; - ((struct ulong_wrapper *)dst)->v = v; - dst += sizeof(unsigned long); - src += sizeof(unsigned long); - } while (dst < end); + const u8 * const end = dst + length; + unsigned long v; + + v = ((struct ulong_wrapper *)src)->v; + ((struct ulong_wrapper *)dst)->v = v; + dst += sizeof(unsigned long); + src += sizeof(unsigned long); + + if (dst < end) { + do { + v = ((struct ulong_wrapper *)src)->v; + ((struct ulong_wrapper *)dst)->v = v; + dst += sizeof(unsigned long); + src += sizeof(unsigned long); + } while (dst < end); + } return; }