diff options
author | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2011-08-07 04:07:26 -0400 |
---|---|---|
committer | Michihiro NAKAJIMA <ggcueroad@gmail.com> | 2011-08-07 04:07:26 -0400 |
commit | ed83bacd7b5d8b2325573efef0bb46ffdba06f91 (patch) | |
tree | ef4ec9e8a03ebdc8e1e10b1ab96e27e5dd579809 | |
parent | 9cadbdf232555f7abf4062b6aac7f56e0dab1da5 (diff) | |
download | libarchive-ed83bacd7b5d8b2325573efef0bb46ffdba06f91.tar.gz |
Effectively read compressed data into a cache buffer of bit readers
without bytes-swap functions. A use of our byte-swap functions needed
extra bit shifts at bit readers.
SVN-Revision: 3550
-rw-r--r-- | libarchive/archive_read_support_format_cab.c | 26 | ||||
-rw-r--r-- | libarchive/archive_read_support_format_lha.c | 30 | ||||
-rw-r--r-- | libarchive/archive_read_support_format_rar.c | 30 |
3 files changed, 60 insertions, 26 deletions
diff --git a/libarchive/archive_read_support_format_cab.c b/libarchive/archive_read_support_format_cab.c index 975aca46..01da222c 100644 --- a/libarchive/archive_read_support_format_cab.c +++ b/libarchive/archive_read_support_format_cab.c @@ -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; diff --git a/libarchive/archive_read_support_format_lha.c b/libarchive/archive_read_support_format_lha.c index 0f6b3416..f903e929 100644 --- a/libarchive/archive_read_support_format_lha.c +++ b/libarchive/archive_read_support_format_lha.c @@ -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; diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c index 15f87cf6..42e4f00d 100644 --- a/libarchive/archive_read_support_format_rar.c +++ b/libarchive/archive_read_support_format_rar.c @@ -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; |