Skip to content

Commit

Permalink
Prefer OR over addition (#1915)
Browse files Browse the repository at this point in the history
Also cast all being ORed to uint64_t when creating a uint64_t.

This makes the code more idiomatic to compilers.
  • Loading branch information
AtariDreams committed Jul 9, 2023
1 parent 2d5a37b commit 7e3c1cf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions libarchive/archive_read_support_format_cab.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,10 +2294,10 @@ lzx_br_fillup(struct lzx_stream *strm, struct lzx_br *br)
(br->cache_buffer << 48) |
((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];
((uint64_t)strm->next_in[3]) << 24 |
((uint64_t)strm->next_in[2]) << 16 |
((uint64_t)strm->next_in[5]) << 8 |
(uint64_t)strm->next_in[4];
strm->next_in += 6;
strm->avail_in -= 6;
br->cache_avail += 6 * 8;
Expand Down
4 changes: 2 additions & 2 deletions libarchive/archive_read_support_format_cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,14 @@ archive_read_format_cpio_cleanup(struct archive_read *a)
static int64_t
le4(const unsigned char *p)
{
return ((p[0] << 16) + (((int64_t)p[1]) << 24) + (p[2] << 0) + (p[3] << 8));
return ((p[0] << 16) | (((int64_t)p[1]) << 24) | (p[2] << 0) | (p[3] << 8));
}


static int64_t
be4(const unsigned char *p)
{
return ((((int64_t)p[0]) << 24) + (p[1] << 16) + (p[2] << 8) + (p[3]));
return ((((int64_t)p[0]) << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]));
}

/*
Expand Down
16 changes: 8 additions & 8 deletions libarchive/archive_read_support_format_lha.c
Original file line number Diff line number Diff line change
Expand Up @@ -2009,10 +2009,10 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
((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];
((uint64_t)strm->next_in[3]) << 24 |
((uint64_t)strm->next_in[4]) << 16 |
((uint64_t)strm->next_in[5]) << 8 |
(uint64_t)strm->next_in[6];
strm->next_in += 7;
strm->avail_in -= 7;
br->cache_avail += 7 * 8;
Expand All @@ -2022,10 +2022,10 @@ lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br)
(br->cache_buffer << 48) |
((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];
((uint64_t)strm->next_in[2]) << 24 |
((uint64_t)strm->next_in[3]) << 16 |
((uint64_t)strm->next_in[4]) << 8 |
(uint64_t)strm->next_in[5];
strm->next_in += 6;
strm->avail_in -= 6;
br->cache_avail += 6 * 8;
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_read_support_format_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ zip_read_data_zipx_bzip2(struct archive_read *a, const void **buff,
to_consume = zip->bzstream.total_in_lo32;
__archive_read_consume(a, to_consume);

total_out = ((uint64_t) zip->bzstream.total_out_hi32 << 32) +
total_out = ((uint64_t) zip->bzstream.total_out_hi32 << 32) |
zip->bzstream.total_out_lo32;

zip->entry_bytes_remaining -= to_consume;
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_write_add_filter_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ archive_compressor_compress_write(struct archive_write_filter *f,
while (length--) {
c = *bp++;
state->in_count++;
state->cur_fcode = (c << 16) + state->cur_code;
state->cur_fcode = (c << 16) | state->cur_code;
i = ((c << HSHIFT) ^ state->cur_code); /* Xor hashing. */

if (state->hashtab[i] == state->cur_fcode) {
Expand Down
4 changes: 2 additions & 2 deletions libarchive/archive_write_disk_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ static ssize_t _archive_write_disk_data_block(struct archive *, const void *,
* which is high-16-bits of nFileIndexHigh. */
#define bhfi_ino(bhfi) \
((((int64_t)((bhfi)->nFileIndexHigh & 0x0000FFFFUL)) << 32) \
+ (bhfi)->nFileIndexLow)
| (bhfi)->nFileIndexLow)
#define bhfi_size(bhfi) \
((((int64_t)(bhfi)->nFileSizeHigh) << 32) + (bhfi)->nFileSizeLow)
((((int64_t)(bhfi)->nFileSizeHigh) << 32) | (bhfi)->nFileSizeLow)

static int
file_information(struct archive_write_disk *a, wchar_t *path,
Expand Down

0 comments on commit 7e3c1cf

Please sign in to comment.