]> wimlib.net Git - wimlib/commitdiff
lz_copy(): Unroll first iteration
authorEric Biggers <ebiggers3@gmail.com>
Sat, 6 Sep 2014 16:54:16 +0000 (11:54 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 6 Sep 2014 16:54:31 +0000 (11:54 -0500)
Most matches are short, so 1 iteration is the most common case.
Use separate branch for this.

include/wimlib/decompress_common.h

index da15fd1eef93176e1d34eb616785503cb78d8c4f..3f3742a02ea750aad757febe523109b9441954d6 100644 (file)
@@ -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;
        }