From 0158ecdaa9e7475a75799f369468f9af5a8ce4ea Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 6 Sep 2014 11:54:16 -0500 Subject: [PATCH] lz_copy(): Unroll first iteration Most matches are short, so 1 iteration is the most common case. Use separate branch for this. --- include/wimlib/decompress_common.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) 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; } -- 2.43.0