]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Effectively read compressed data into a cache buffer of bit readers
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 7 Aug 2011 08:07:26 +0000 (04:07 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 7 Aug 2011 08:07:26 +0000 (04:07 -0400)
without bytes-swap functions. A use of our byte-swap functions needed
extra bit shifts at bit readers.

SVN-Revision: 3550

libarchive/archive_read_support_format_cab.c
libarchive/archive_read_support_format_lha.c
libarchive/archive_read_support_format_rar.c

index 975aca460a9b945bfa0a2dffb11b8dc0206717b5..01da222cbe11378080f1f095bf649fa1081cadba 100644 (file)
@@ -2254,13 +2254,14 @@ lzx_br_fillup(struct lzx_stream *strm, struct lzx_br *br)
                case 4:
                        if (strm->avail_in >= 8) {
                                br->cache_buffer =
-                                   (((uint64_t)archive_le16dec(
-                                       strm->next_in)) << 48) |
-                                   (((uint64_t)archive_le16dec(
-                                       strm->next_in+2)) << 32) |
-                                   (((uint32_t)archive_le16dec(
-                                       strm->next_in+4)) << 16) |
-                                   archive_le16dec(strm->next_in+6);
+                                   ((uint64_t)strm->next_in[1]) << 56 |
+                                   ((uint64_t)strm->next_in[0]) << 48 |
+                                   ((uint64_t)strm->next_in[3]) << 40 |
+                                   ((uint64_t)strm->next_in[2]) << 32 |
+                                   ((uint32_t)strm->next_in[5]) << 24 |
+                                   ((uint32_t)strm->next_in[4]) << 16 |
+                                   ((uint32_t)strm->next_in[7]) << 8 |
+                                    (uint32_t)strm->next_in[6];
                                strm->next_in += 8;
                                strm->avail_in -= 8;
                                br->cache_avail += 8 * 8;
@@ -2271,11 +2272,12 @@ lzx_br_fillup(struct lzx_stream *strm, struct lzx_br *br)
                        if (strm->avail_in >= 6) {
                                br->cache_buffer =
                                   (br->cache_buffer << 48) |
-                                   (((uint64_t)archive_le16dec(
-                                       strm->next_in)) << 32) |
-                                   (((uint32_t)archive_le16dec(
-                                       strm->next_in+2)) << 16) |
-                                   archive_le16dec(strm->next_in+4);
+                                   ((uint64_t)strm->next_in[1]) << 40 |
+                                   ((uint64_t)strm->next_in[0]) << 32 |
+                                   ((uint32_t)strm->next_in[3]) << 24 |
+                                   ((uint32_t)strm->next_in[2]) << 16 |
+                                   ((uint32_t)strm->next_in[5]) << 8 |
+                                    (uint32_t)strm->next_in[4];
                                strm->next_in += 6;
                                strm->avail_in -= 6;
                                br->cache_avail += 6 * 8;
index 0f6b34164fabb0e0c7f90be747bc458504afb1ef..f903e92945bac8bb4a21c5d5655c47d585ff5d0b 100644 (file)
@@ -1838,7 +1838,7 @@ lzh_decode_free(struct lzh_stream *strm)
  *          bytes. */
 #define lzh_br_read_ahead(strm, br, n) \
        (lzh_br_has(br, (n)) || lzh_br_fillup(strm, br))
-/* Notify how man bits we consumed. */
+/* Notify how many bits we consumed. */
 #define lzh_br_consume(br, n)  ((br)->cache_avail -= (n))
 #define lzh_br_unconsume(br, n)        ((br)->cache_avail += (n))
 
@@ -1867,7 +1867,14 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
                case 8:
                        if (strm->avail_in >= 8) {
                                br->cache_buffer =
-                                   archive_be64dec(strm->next_in);
+                                   ((uint64_t)strm->next_in[0]) << 56 |
+                                   ((uint64_t)strm->next_in[1]) << 48 |
+                                   ((uint64_t)strm->next_in[2]) << 40 |
+                                   ((uint64_t)strm->next_in[3]) << 32 |
+                                   ((uint32_t)strm->next_in[4]) << 24 |
+                                   ((uint32_t)strm->next_in[5]) << 16 |
+                                   ((uint32_t)strm->next_in[6]) << 8 |
+                                    (uint32_t)strm->next_in[7];
                                strm->next_in += 8;
                                strm->avail_in -= 8;
                                br->cache_avail += 8 * 8;
@@ -1875,10 +1882,16 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
                        }
                        break;
                case 7:
-                       if (strm->avail_in >= 8) {/* Read extra one. */
+                       if (strm->avail_in >= 7) {
                                br->cache_buffer =
                                   (br->cache_buffer << 56) |
-                                   archive_be64dec(strm->next_in) >> 8;
+                                   ((uint64_t)strm->next_in[0]) << 48 |
+                                   ((uint64_t)strm->next_in[1]) << 40 |
+                                   ((uint64_t)strm->next_in[2]) << 32 |
+                                   ((uint32_t)strm->next_in[3]) << 24 |
+                                   ((uint32_t)strm->next_in[4]) << 16 |
+                                   ((uint32_t)strm->next_in[5]) << 8 |
+                                    (uint32_t)strm->next_in[6];
                                strm->next_in += 7;
                                strm->avail_in -= 7;
                                br->cache_avail += 7 * 8;
@@ -1889,9 +1902,12 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
                        if (strm->avail_in >= 6) {
                                br->cache_buffer =
                                   (br->cache_buffer << 48) |
-                                  (((uint64_t)archive_be32dec(
-                                      strm->next_in)) << 16) |
-                                   archive_be16dec(&strm->next_in[4]);
+                                   ((uint64_t)strm->next_in[0]) << 40 |
+                                   ((uint64_t)strm->next_in[1]) << 32 |
+                                   ((uint32_t)strm->next_in[2]) << 24 |
+                                   ((uint32_t)strm->next_in[3]) << 16 |
+                                   ((uint32_t)strm->next_in[4]) << 8 |
+                                    (uint32_t)strm->next_in[5];
                                strm->next_in += 6;
                                strm->avail_in -= 6;
                                br->cache_avail += 6 * 8;
index 15f87cf6ae663e931ac571a59acae972d8631a8b..42e4f00d83101298bc7f693e64d24b724507fb66 100644 (file)
@@ -311,7 +311,7 @@ static int copy_from_lzss_window(struct archive_read *, const void **,
  *  False : there is no data in the stream. */
 #define rar_br_read_ahead(a, br, n) \
   ((rar_br_has(br, (n)) || rar_br_fillup(a, br)) || rar_br_has(br, (n)))
-/* Notify how man bits we consumed. */
+/* Notify how many bits we consumed. */
 #define rar_br_consume(br, n) ((br)->cache_avail -= (n))
 #define rar_br_consume_unalined_bits(br) ((br)->cache_avail &= ~7)
 
@@ -345,7 +345,14 @@ rar_br_fillup(struct archive_read *a, struct rar_br *br)
     case 8:
       if (br->avail_in >= 8) {
         br->cache_buffer =
-            archive_be64dec(br->next_in);
+            ((uint64_t)br->next_in[0]) << 56 |
+            ((uint64_t)br->next_in[1]) << 48 |
+            ((uint64_t)br->next_in[2]) << 40 |
+            ((uint64_t)br->next_in[3]) << 32 |
+            ((uint32_t)br->next_in[4]) << 24 |
+            ((uint32_t)br->next_in[5]) << 16 |
+            ((uint32_t)br->next_in[6]) << 8 |
+             (uint32_t)br->next_in[7];
         br->next_in += 8;
         br->avail_in -= 8;
         br->cache_avail += 8 * 8;
@@ -355,10 +362,16 @@ rar_br_fillup(struct archive_read *a, struct rar_br *br)
       }
       break;
     case 7:
-      if (br->avail_in >= 8) {/* Read extra one. */
+      if (br->avail_in >= 7) {
         br->cache_buffer =
            (br->cache_buffer << 56) |
-            archive_be64dec(br->next_in) >> 8;
+            ((uint64_t)br->next_in[0]) << 48 |
+            ((uint64_t)br->next_in[1]) << 40 |
+            ((uint64_t)br->next_in[2]) << 32 |
+            ((uint32_t)br->next_in[3]) << 24 |
+            ((uint32_t)br->next_in[4]) << 16 |
+            ((uint32_t)br->next_in[5]) << 8 |
+             (uint32_t)br->next_in[6];
         br->next_in += 7;
         br->avail_in -= 7;
         br->cache_avail += 7 * 8;
@@ -371,9 +384,12 @@ rar_br_fillup(struct archive_read *a, struct rar_br *br)
       if (br->avail_in >= 6) {
         br->cache_buffer =
            (br->cache_buffer << 48) |
-           (((uint64_t)archive_be32dec(
-               br->next_in)) << 16) |
-            archive_be16dec(&br->next_in[4]);
+            ((uint64_t)br->next_in[0]) << 40 |
+            ((uint64_t)br->next_in[1]) << 32 |
+            ((uint32_t)br->next_in[2]) << 24 |
+            ((uint32_t)br->next_in[3]) << 16 |
+            ((uint32_t)br->next_in[4]) << 8 |
+             (uint32_t)br->next_in[5];
         br->next_in += 6;
         br->avail_in -= 6;
         br->cache_avail += 6 * 8;