Misc. cleanups
authorEric Biggers <ebiggers3@gmail.com>
Sat, 3 Jan 2015 00:25:50 +0000 (18:25 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 3 Jan 2015 00:40:01 +0000 (18:40 -0600)
include/wimlib/bt_matchfinder.h
include/wimlib/decompress_common.h
include/wimlib/hc_matchfinder.h
include/wimlib/lz_extend.h
include/wimlib/matchfinder_common.h
include/wimlib/unaligned.h
src/compress_common.c
src/decompress_common.c
src/error.c

index 75858a3..43654c5 100644 (file)
@@ -27,7 +27,8 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#pragma once
+#ifndef _BT_MATCHFINDER_H
+#define _BT_MATCHFINDER_H
 
 #include "wimlib/lz_extend.h"
 #include "wimlib/lz_hash3.h"
@@ -226,3 +227,5 @@ bt_matchfinder_skip_position(struct bt_matchfinder * const restrict mf,
                }
        }
 }
+
+#endif /* _BT_MATCHFINDER_H */
index b6927be..8ed98ca 100644 (file)
@@ -10,7 +10,6 @@
 #ifndef _WIMLIB_DECOMPRESS_COMMON_H
 #define _WIMLIB_DECOMPRESS_COMMON_H
 
-#include "wimlib/assert.h"
 #include "wimlib/compiler.h"
 #include "wimlib/endianness.h"
 #include "wimlib/types.h"
@@ -253,6 +252,25 @@ make_huffman_decode_table(u16 decode_table[], unsigned num_syms,
                          unsigned num_bits, const u8 lens[],
                          unsigned max_codeword_len);
 
+static inline void
+copy_word_unaligned(const void *src, void *dst)
+{
+       store_word_unaligned(load_word_unaligned(src), dst);
+}
+
+static inline machine_word_t
+repeat_byte(u8 b)
+{
+       machine_word_t v;
+
+       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+
+       v = b;
+       v |= v << 8;
+       v |= v << 16;
+       v |= v << ((WORDSIZE == 8) ? 32 : 0);
+       return v;
+}
 
 /*
  * Copy an LZ77 match at (dst - offset) to dst.
index d880b24..02271ff 100644 (file)
@@ -27,7 +27,8 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#pragma once
+#ifndef _HC_MATCHFINDER_H
+#define _HC_MATCHFINDER_H
 
 #include "wimlib/lz_extend.h"
 #include "wimlib/lz_hash3.h"
@@ -52,7 +53,7 @@ struct hc_matchfinder {
                pos_t mf_data[HC_MATCHFINDER_TOTAL_LENGTH];
                struct {
                        pos_t hash_tab[HC_MATCHFINDER_HASH_LENGTH];
-                       pos_t child_tab[MATCHFINDER_WINDOW_SIZE];
+                       pos_t next_tab[MATCHFINDER_WINDOW_SIZE];
                };
        };
 } _aligned_attribute(MATCHFINDER_ALIGNMENT);
@@ -123,7 +124,7 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
        first_3_bytes = load_u24_unaligned(in_next);
        hash = lz_hash_u24(first_3_bytes, HC_MATCHFINDER_HASH_ORDER);
        cur_match = mf->hash_tab[hash];
-       mf->child_tab[in_next - in_base] = cur_match;
+       mf->next_tab[in_next - in_base] = cur_match;
        mf->hash_tab[hash] = in_next - in_base;
 
        if (unlikely(best_len >= max_len))
@@ -144,7 +145,7 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
                                break;
 
                        /* Not a match; keep trying.  */
-                       cur_match = mf->child_tab[
+                       cur_match = mf->next_tab[
                                        matchfinder_slot_for_match(cur_match)];
                        if (!matchfinder_match_in_window(cur_match,
                                                         in_base, in_next))
@@ -158,7 +159,7 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
                best_len = lz_extend(in_next, best_matchptr, 3, max_len);
                if (best_len >= nice_len)
                        goto out;
-               cur_match = mf->child_tab[matchfinder_slot_for_match(cur_match)];
+               cur_match = mf->next_tab[matchfinder_slot_for_match(cur_match)];
                if (!matchfinder_match_in_window(cur_match, in_base, in_next))
                        goto out;
                if (!--depth_remaining)
@@ -181,18 +182,17 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
                #endif
                                break;
 
-                       cur_match = mf->child_tab[matchfinder_slot_for_match(cur_match)];
+                       cur_match = mf->next_tab[matchfinder_slot_for_match(cur_match)];
                        if (!matchfinder_match_in_window(cur_match, in_base, in_next))
                                goto out;
                        if (!--depth_remaining)
                                goto out;
                }
 
-       #if UNALIGNED_ACCESS_IS_FAST
-               len = 4;
-       #else
-               len = 0;
-       #endif
+               if (UNALIGNED_ACCESS_IS_FAST)
+                       len = 4;
+               else
+                       len = 0;
                len = lz_extend(in_next, matchptr, len, max_len);
                if (len > best_len) {
                        best_len = len;
@@ -200,7 +200,7 @@ hc_matchfinder_longest_match(struct hc_matchfinder * const restrict mf,
                        if (best_len >= nice_len)
                                goto out;
                }
-               cur_match = mf->child_tab[matchfinder_slot_for_match(cur_match)];
+               cur_match = mf->next_tab[matchfinder_slot_for_match(cur_match)];
                if (!matchfinder_match_in_window(cur_match, in_base, in_next))
                        goto out;
                if (!--depth_remaining)
@@ -240,8 +240,10 @@ hc_matchfinder_skip_positions(struct hc_matchfinder * restrict mf,
 
        do {
                hash = lz_hash(in_next, HC_MATCHFINDER_HASH_ORDER);
-               mf->child_tab[in_next - in_base] = mf->hash_tab[hash];
+               mf->next_tab[in_next - in_base] = mf->hash_tab[hash];
                mf->hash_tab[hash] = in_next - in_base;
                in_next++;
        } while (--count);
 }
+
+#endif /* _HC_MATCHFINDER_H */
index d47e097..a3780e1 100644 (file)
@@ -20,10 +20,9 @@ lz_extend(const u8 * const strptr, const u8 * const matchptr,
          const u32 start_len, const u32 max_len)
 {
        u32 len = start_len;
+       machine_word_t v_word;
 
-       if (UNALIGNED_ACCESS_IS_FAST && CPU_IS_LITTLE_ENDIAN) {
-
-               machine_word_t v_word;
+       if (UNALIGNED_ACCESS_IS_FAST) {
 
                if (likely(max_len - len >= 4 * WORDSIZE)) {
 
@@ -48,18 +47,18 @@ lz_extend(const u8 * const strptr, const u8 * const matchptr,
                                goto word_differs;
                        len += WORDSIZE;
                }
+       }
 
-               while (len < max_len && matchptr[len] == strptr[len])
-                       len++;
-               return len;
+       while (len < max_len && matchptr[len] == strptr[len])
+               len++;
+       return len;
 
-       word_differs:
-               return len + (ffsw(v_word) >> 3);
-       } else {
-               while (len < max_len && matchptr[len] == strptr[len])
-                       len++;
-               return len;
-       }
+word_differs:
+       if (CPU_IS_LITTLE_ENDIAN)
+               len += (ffsw(v_word) >> 3);
+       else
+               len += (flsw(v_word) >> 3);
+       return len;
 }
 
 #endif /* _WIMLIB_LZ_EXTEND_H */
index afaab9c..66a966a 100644 (file)
@@ -29,7 +29,8 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#pragma once
+#ifndef _MATCHFINDER_COMMON_H
+#define _MATCHFINDER_COMMON_H
 
 #include "wimlib/types.h"
 
@@ -186,3 +187,5 @@ matchfinder_rebase(pos_t *data, size_t num_entries)
        }
 }
 #endif /* MATCHFINDER_IS_SLIDING */
+
+#endif /* _MATCHFINDER_COMMON_H */
index ccc86f0..5f920e7 100644 (file)
@@ -46,26 +46,6 @@ DEFINE_UNALIGNED_TYPE(machine_word_t);
 #define load_word_unaligned    load_machine_word_t_unaligned
 #define store_word_unaligned   store_machine_word_t_unaligned
 
-static inline void
-copy_word_unaligned(const void *src, void *dst)
-{
-       store_word_unaligned(load_word_unaligned(src), dst);
-}
-
-static inline machine_word_t
-repeat_byte(u8 b)
-{
-       machine_word_t v;
-
-       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
-
-       v = b;
-       v |= v << 8;
-       v |= v << 16;
-       v |= v << ((WORDSIZE == 8) ? 32 : 0);
-       return v;
-}
-
 static inline u16
 get_unaligned_u16_le(const void *p)
 {
index 7ca7f5b..f743095 100644 (file)
@@ -14,7 +14,6 @@
 #  include "config.h"
 #endif
 
-#include "wimlib/assert.h"
 #include "wimlib/compress_common.h"
 #include "wimlib/util.h"
 
index f89fc4f..49cd5ba 100644 (file)
@@ -14,7 +14,6 @@
 #  include "config.h"
 #endif
 
-#include "wimlib/assert.h"
 #include "wimlib/decompress_common.h"
 
 #include <string.h>
index 627d1c2..30087ae 100644 (file)
@@ -55,36 +55,34 @@ static bool wimlib_owns_error_file = false;
 
 #if defined(ENABLE_ERROR_MESSAGES) || defined(ENABLE_DEBUG)
 static void
-wimlib_vmsg(const tchar *tag, const tchar *format,
-           va_list va, bool perror)
+wimlib_vmsg(const tchar *tag, const tchar *format, va_list va, bool perror)
 {
-#if !defined(ENABLE_DEBUG)
-       if (wimlib_print_errors)
+#ifndef ENABLE_DEBUG
+       if (!wimlib_print_errors)
+               return;
 #endif
-       {
-               int errno_save = errno;
-               fflush(stdout);
-               tfputs(tag, wimlib_error_file);
-               tvfprintf(wimlib_error_file, format, va);
-               if (perror && errno_save != 0) {
-                       tchar buf[64];
-                       int res;
-                       res = tstrerror_r(errno_save, buf, ARRAY_LEN(buf));
-                       if (res) {
-                               tsprintf(buf,
-                                        T("unknown error (errno=%d)"),
-                                        errno_save);
-                       }
-               #ifdef WIN32
-                       if (errno_save == EBUSY)
-                               tstrcpy(buf, T("Resource busy"));
-               #endif
-                       tfprintf(wimlib_error_file, T(": %"TS), buf);
+       int errno_save = errno;
+       fflush(stdout);
+       tfputs(tag, wimlib_error_file);
+       tvfprintf(wimlib_error_file, format, va);
+       if (perror && errno_save != 0) {
+               tchar buf[64];
+               int res;
+               res = tstrerror_r(errno_save, buf, ARRAY_LEN(buf));
+               if (res) {
+                       tsprintf(buf,
+                                T("unknown error (errno=%d)"),
+                                errno_save);
                }
-               tputc(T('\n'), wimlib_error_file);
-               fflush(wimlib_error_file);
-               errno = errno_save;
+       #ifdef WIN32
+               if (errno_save == EBUSY)
+                       tstrcpy(buf, T("Resource busy"));
+       #endif
+               tfprintf(wimlib_error_file, T(": %"TS), buf);
        }
+       tputc(T('\n'), wimlib_error_file);
+       fflush(wimlib_error_file);
+       errno = errno_save;
 }
 #endif