]> wimlib.net Git - wimlib/commitdiff
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 75858a33ebe6157f592bce6274fed700362332e5..43654c5b0acf83f45bca7358171f18fd23a506af 100644 (file)
@@ -27,7 +27,8 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
  * 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"
 
 #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 b6927bed556dc442f3364d52a1fb2b5e3e718fa6..8ed98ca83f97b48cd981dd1b2fa56ab0e31dffba 100644 (file)
@@ -10,7 +10,6 @@
 #ifndef _WIMLIB_DECOMPRESS_COMMON_H
 #define _WIMLIB_DECOMPRESS_COMMON_H
 
 #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"
 #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);
 
                          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.
 
 /*
  * Copy an LZ77 match at (dst - offset) to dst.
index d880b2486d647ec40ec5b9d030826984e7b5eb4b..02271ff4a0c2d0164909d48e538870dbea8ea8e5 100644 (file)
@@ -27,7 +27,8 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
  * 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"
 
 #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 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);
                };
        };
 } _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];
        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))
        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.  */
                                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))
                                        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;
                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)
                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;
 
                #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 (!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;
                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;
                }
                        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)
                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);
 
        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);
 }
                mf->hash_tab[hash] = in_next - in_base;
                in_next++;
        } while (--count);
 }
+
+#endif /* _HC_MATCHFINDER_H */
index d47e0976d5836ff0214dcfc6563bec63911a559d..a3780e1d54a819245b980dc36439d0ddc7d2a3ab 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;
          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)) {
 
 
                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;
                }
                                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 */
 }
 
 #endif /* _WIMLIB_LZ_EXTEND_H */
index afaab9cba01e61a5b1eab8a1b5fe461681e31c74..66a966a36655ccc8091c0ed3816246d804f2acf4 100644 (file)
@@ -29,7 +29,8 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#pragma once
+#ifndef _MATCHFINDER_COMMON_H
+#define _MATCHFINDER_COMMON_H
 
 #include "wimlib/types.h"
 
 
 #include "wimlib/types.h"
 
@@ -186,3 +187,5 @@ matchfinder_rebase(pos_t *data, size_t num_entries)
        }
 }
 #endif /* MATCHFINDER_IS_SLIDING */
        }
 }
 #endif /* MATCHFINDER_IS_SLIDING */
+
+#endif /* _MATCHFINDER_COMMON_H */
index ccc86f016a3ab9a1638e49a1bf42891e437d0a8e..5f920e75d30c5a53b39a5bdf099a176bc204b945 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
 
 #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)
 {
 static inline u16
 get_unaligned_u16_le(const void *p)
 {
index 7ca7f5bba312831b9d342af875acaf2c19f144a0..f74309583a994e263762691c84ea33ec64a0dd7d 100644 (file)
@@ -14,7 +14,6 @@
 #  include "config.h"
 #endif
 
 #  include "config.h"
 #endif
 
-#include "wimlib/assert.h"
 #include "wimlib/compress_common.h"
 #include "wimlib/util.h"
 
 #include "wimlib/compress_common.h"
 #include "wimlib/util.h"
 
index f89fc4f35538370bf1651939cd163f60373d9b30..49cd5ba0f083afa64248246080830fd93dfbb589 100644 (file)
@@ -14,7 +14,6 @@
 #  include "config.h"
 #endif
 
 #  include "config.h"
 #endif
 
-#include "wimlib/assert.h"
 #include "wimlib/decompress_common.h"
 
 #include <string.h>
 #include "wimlib/decompress_common.h"
 
 #include <string.h>
index 627d1c2776ecabec10e49796ac42e91277a197ae..30087aefb66d6e4b4a046dfa2506fcee0b138993 100644 (file)
@@ -55,36 +55,34 @@ static bool wimlib_owns_error_file = false;
 
 #if defined(ENABLE_ERROR_MESSAGES) || defined(ENABLE_DEBUG)
 static void
 
 #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
 #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
 
 }
 #endif