Merge pull request #268 from eustas/master

Add more explicit type conversions.
This commit is contained in:
eustas 2015-11-17 17:01:44 +01:00
commit befc549b47
6 changed files with 15 additions and 14 deletions

View File

@ -18,6 +18,7 @@
#ifndef BROTLI_DEC_BIT_READER_H_ #ifndef BROTLI_DEC_BIT_READER_H_
#define BROTLI_DEC_BIT_READER_H_ #define BROTLI_DEC_BIT_READER_H_
#include <stdio.h>
#include <string.h> #include <string.h>
#include "./port.h" #include "./port.h"
#include "./types.h" #include "./types.h"

View File

@ -546,8 +546,6 @@ bool BrotliCompressor::WriteMetadata(const size_t input_size,
if (input_size == 0) { if (input_size == 0) {
WriteBits(2, 0, &storage_ix, encoded_buffer); WriteBits(2, 0, &storage_ix, encoded_buffer);
*encoded_size = (storage_ix + 7) >> 3; *encoded_size = (storage_ix + 7) >> 3;
} else if (input_size > (1 << 24)) {
return false;
} else { } else {
int nbits = Log2Floor(static_cast<uint32_t>(input_size) - 1) + 1; int nbits = Log2Floor(static_cast<uint32_t>(input_size) - 1) + 1;
int nbytes = (nbits + 7) / 8; int nbytes = (nbits + 7) / 8;

View File

@ -79,7 +79,7 @@ class BrotliCompressor {
~BrotliCompressor(); ~BrotliCompressor();
// The maximum input size that can be processed at once. // The maximum input size that can be processed at once.
size_t input_block_size() const { return 1 << params_.lgblock; } size_t input_block_size() const { return size_t(1) << params_.lgblock; }
// Encodes the data in input_buffer as a meta-block and writes it to // Encodes the data in input_buffer as a meta-block and writes it to
// encoded_buffer (*encoded_size should be set to the size of // encoded_buffer (*encoded_size should be set to the size of

View File

@ -510,7 +510,7 @@ class HashLongestMatch {
if (len > kMaxZopfliLen) { if (len > kMaxZopfliLen) {
matches = orig_matches; matches = orig_matches;
} }
*matches++ = BackwardMatch(backward, len); *matches++ = BackwardMatch(static_cast<int>(backward), len);
} }
} }
const uint32_t key = HashBytes(&data[cur_ix_masked]); const uint32_t key = HashBytes(&data[cur_ix_masked]);

View File

@ -32,11 +32,12 @@ class RingBuffer {
public: public:
RingBuffer(int window_bits, int tail_bits) RingBuffer(int window_bits, int tail_bits)
: window_bits_(window_bits), : window_bits_(window_bits),
mask_((1 << window_bits) - 1), size_((size_t(1) << window_bits)),
tail_size_(1 << tail_bits), mask_((size_t(1) << window_bits) - 1),
tail_size_(size_t(1) << tail_bits),
pos_(0) { pos_(0) {
static const int kSlackForEightByteHashingEverywhere = 7; static const int kSlackForEightByteHashingEverywhere = 7;
const size_t buflen = (1 << window_bits_) + tail_size_; const size_t buflen = size_ + tail_size_;
buffer_ = new uint8_t[buflen + kSlackForEightByteHashingEverywhere]; buffer_ = new uint8_t[buflen + kSlackForEightByteHashingEverywhere];
for (int i = 0; i < kSlackForEightByteHashingEverywhere; ++i) { for (int i = 0; i < kSlackForEightByteHashingEverywhere; ++i) {
buffer_[buflen + i] = 0; buffer_[buflen + i] = 0;
@ -52,17 +53,17 @@ class RingBuffer {
// The length of the writes is limited so that we do not need to worry // The length of the writes is limited so that we do not need to worry
// about a write // about a write
WriteTail(bytes, n); WriteTail(bytes, n);
if (PREDICT_TRUE(masked_pos + n <= (1U << window_bits_))) { if (PREDICT_TRUE(masked_pos + n <= size_)) {
// A single write fits. // A single write fits.
memcpy(&buffer_[masked_pos], bytes, n); memcpy(&buffer_[masked_pos], bytes, n);
} else { } else {
// Split into two writes. // Split into two writes.
// Copy into the end of the buffer, including the tail buffer. // Copy into the end of the buffer, including the tail buffer.
memcpy(&buffer_[masked_pos], bytes, memcpy(&buffer_[masked_pos], bytes,
std::min(n, ((1 << window_bits_) + tail_size_) - masked_pos)); std::min(n, (size_ + tail_size_) - masked_pos));
// Copy into the beginning of the buffer // Copy into the beginning of the buffer
memcpy(&buffer_[0], bytes + ((1 << window_bits_) - masked_pos), memcpy(&buffer_[0], bytes + (size_ - masked_pos),
n - ((1 << window_bits_) - masked_pos)); n - (size_ - masked_pos));
} }
pos_ += n; pos_ += n;
} }
@ -85,13 +86,14 @@ class RingBuffer {
const size_t masked_pos = pos_ & mask_; const size_t masked_pos = pos_ & mask_;
if (PREDICT_FALSE(masked_pos < tail_size_)) { if (PREDICT_FALSE(masked_pos < tail_size_)) {
// Just fill the tail buffer with the beginning data. // Just fill the tail buffer with the beginning data.
const size_t p = (1 << window_bits_) + masked_pos; const size_t p = size_ + masked_pos;
memcpy(&buffer_[p], bytes, std::min(n, tail_size_ - masked_pos)); memcpy(&buffer_[p], bytes, std::min(n, tail_size_ - masked_pos));
} }
} }
// Size of the ringbuffer is (1 << window_bits) + tail_size_. // Size of the ringbuffer is (1 << window_bits) + tail_size_.
const int window_bits_; const int window_bits_;
const size_t size_;
const size_t mask_; const size_t mask_;
const size_t tail_size_; const size_t tail_size_;

View File

@ -66,12 +66,12 @@ inline void WriteBits(int n_bits,
uint8_t *array_pos = &array[*pos >> 3]; uint8_t *array_pos = &array[*pos >> 3];
const int bits_reserved_in_first_byte = (*pos & 7); const int bits_reserved_in_first_byte = (*pos & 7);
bits <<= bits_reserved_in_first_byte; bits <<= bits_reserved_in_first_byte;
*array_pos++ |= bits; *array_pos++ |= static_cast<uint8_t>(bits);
for (int bits_left_to_write = n_bits - 8 + bits_reserved_in_first_byte; for (int bits_left_to_write = n_bits - 8 + bits_reserved_in_first_byte;
bits_left_to_write >= 1; bits_left_to_write >= 1;
bits_left_to_write -= 8) { bits_left_to_write -= 8) {
bits >>= 8; bits >>= 8;
*array_pos++ = bits; *array_pos++ = static_cast<uint8_t>(bits);
} }
*array_pos = 0; *array_pos = 0;
*pos += n_bits; *pos += n_bits;