Compile fixes for GCC 12 and Clang 13

This commit is contained in:
Phillip Stephens 2022-05-14 15:30:26 -07:00
parent 546a969527
commit ee8b4c29ad
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
2 changed files with 31 additions and 35 deletions

View File

@ -339,7 +339,7 @@ public:
}
void init() {
std::fill(std::begin(chain_sz), std::end(chain_sz), 0);
std::fill(chain_sz.begin(), chain_sz.end(), 0);
}
void remove(uint32_t pos, const uint8_t* b) {
@ -412,21 +412,21 @@ public:
s.wind_sz = uint32_t(std::min(src_size, std::size_t(MaxMatchLen)));
s.wind_b = 0;
s.wind_e = s.wind_sz;
std::copy_n(s.inp, s.wind_sz, _storage->buffer);
std::copy_n(s.inp, s.wind_sz, _storage->buffer.data());
s.inp += s.wind_sz;
if (s.wind_e == DictBase::BufSize)
s.wind_e = 0;
if (s.wind_sz < 3)
std::fill_n(_storage->buffer + s.wind_b + s.wind_sz, 3, 0);
std::fill_n(_storage->buffer.data() + s.wind_b + s.wind_sz, 3, 0);
}
void reset_next_input_entry(State& s, Match3Impl& match3, Match2Impl& match2) {
/* Remove match from about-to-be-clobbered buffer entry */
if (s.cycle1_countdown == 0) {
match3.remove(s.wind_e, _storage->buffer);
match2.remove(s.wind_e, _storage->buffer);
match3.remove(s.wind_e, _storage->buffer.data());
match2.remove(s.wind_e, _storage->buffer.data());
} else {
--s.cycle1_countdown;
}
@ -440,9 +440,9 @@ public:
if (skip) {
for (uint32_t i = 0; i < lb_len - 1; ++i) {
reset_next_input_entry(s, match3, match2);
match3.skip_advance(s, _storage->buffer);
match2.add(uint16_t(s.wind_b), _storage->buffer);
s.get_byte(_storage->buffer);
match3.skip_advance(s, _storage->buffer.data());
match2.add(uint16_t(s.wind_b), _storage->buffer.data());
s.get_byte(_storage->buffer.data());
}
}
@ -452,7 +452,7 @@ public:
uint32_t best_pos[MaxMatchByLengthLen] = {};
uint32_t match_pos, match_count;
match3.advance(s, match_pos, match_count, _storage->buffer);
match3.advance(s, match_pos, match_count, _storage->buffer.data());
int best_char = _storage->buffer[s.wind_b];
uint32_t best_len = lb_len;
@ -462,10 +462,10 @@ public:
lb_off = 0;
match3.best_len[s.wind_b] = DictBase::MaxMatchLen + 1;
} else {
if (match2.search(s, lb_pos, lb_len, best_pos, _storage->buffer) && s.wind_sz >= 3) {
if (match2.search(s, lb_pos, lb_len, best_pos, _storage->buffer.data()) && s.wind_sz >= 3) {
for (uint32_t i = 0; i < match_count; ++i, match_pos = match3.chain[match_pos]) {
auto ref_ptr = _storage->buffer + s.wind_b;
auto match_ptr = _storage->buffer + match_pos;
auto ref_ptr = _storage->buffer.data() + s.wind_b;
auto match_ptr = _storage->buffer.data() + match_pos;
auto mismatch = std::mismatch(ref_ptr, ref_ptr + s.wind_sz, match_ptr);
auto match_len = uint32_t(mismatch.first - ref_ptr);
if (match_len < 2)
@ -491,9 +491,9 @@ public:
reset_next_input_entry(s, match3, match2);
match2.add(uint16_t(s.wind_b), _storage->buffer);
match2.add(uint16_t(s.wind_b), _storage->buffer.data());
s.get_byte(_storage->buffer);
s.get_byte(_storage->buffer.data());
if (best_char < 0) {
s.buf_sz = 0;

View File

@ -2,6 +2,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <array>
namespace lzokay {
@ -23,14 +24,14 @@ protected:
/* List encoding of previous 3-byte data matches */
struct Match3 {
uint16_t head[HashSize]; /* key -> chain-head-pos */
uint16_t chain_sz[HashSize]; /* key -> chain-size */
uint16_t chain[BufSize]; /* chain-pos -> next-chain-pos */
uint16_t best_len[BufSize]; /* chain-pos -> best-match-length */
std::array<uint16_t, HashSize> head; /* key -> chain-head-pos */
std::array<uint16_t, HashSize> chain_sz; /* key -> chain-size */
std::array<uint16_t, BufSize> chain; /* chain-pos -> next-chain-pos */
std::array<uint16_t, BufSize> best_len; /* chain-pos -> best-match-length */
};
/* Encoding of 2-byte data matches */
struct Match2 {
uint16_t head[1 << 16]; /* 2-byte-data -> head-pos */
std::array<uint16_t, 1 << 16> head; /* 2-byte-data -> head-pos */
};
struct Data {
@ -42,38 +43,33 @@ protected:
* allocated so the start of the buffer may be replicated at the end,
* therefore providing efficient circular access.
*/
uint8_t buffer[BufSize + MaxMatchLen];
std::array<uint8_t, BufSize + MaxMatchLen> buffer;
};
using storage_type = Data;
storage_type* _storage;
DictBase() = default;
friend struct State;
friend EResult compress(const uint8_t* src, std::size_t src_size,
uint8_t* dst, std::size_t& dst_size, DictBase& dict);
friend EResult compress(const uint8_t* src, std::size_t src_size, uint8_t* dst, std::size_t& dst_size,
DictBase& dict);
};
template <template<typename> class _Alloc = std::allocator>
template <template <typename> class _Alloc = std::allocator>
class Dict : public DictBase {
_Alloc<DictBase::storage_type> _allocator;
public:
Dict() { _storage = _allocator.allocate(1); }
~Dict() { _allocator.deallocate(_storage, 1); }
};
EResult decompress(const uint8_t* src, std::size_t src_size,
uint8_t* dst, std::size_t dst_size,
std::size_t& out_size);
EResult compress(const uint8_t* src, std::size_t src_size,
uint8_t* dst, std::size_t dst_size,
std::size_t& out_size, DictBase& dict);
inline EResult compress(const uint8_t* src, std::size_t src_size,
uint8_t* dst, std::size_t dst_size,
EResult decompress(const uint8_t* src, std::size_t src_size, uint8_t* dst, std::size_t dst_size, std::size_t& out_size);
EResult compress(const uint8_t* src, std::size_t src_size, uint8_t* dst, std::size_t dst_size, std::size_t& out_size,
DictBase& dict);
inline EResult compress(const uint8_t* src, std::size_t src_size, uint8_t* dst, std::size_t dst_size,
std::size_t& out_size) {
Dict<> dict;
return compress(src, src_size, dst, dst_size, out_size, dict);
}
constexpr std::size_t compress_worst_size(std::size_t s) {
return s + s / 16 + 64 + 3;
}
constexpr std::size_t compress_worst_size(std::size_t s) { return s + s / 16 + 64 + 3; }
}
} // namespace lzokay