mirror of
https://github.com/google/brotli.git
synced 2024-11-22 19:50:06 +00:00
Fix sign-comparison warnings
+ add more debug runtime checks + minor cleanup
This commit is contained in:
parent
b64b2cf43d
commit
bb26d1919f
@ -290,12 +290,12 @@ void ClusterBlocks(const DataType* data, const size_t length,
|
||||
std::vector<HistogramType> clustered_histograms;
|
||||
std::vector<int> histogram_symbols;
|
||||
// Block ids need to fit in one byte.
|
||||
static const int kMaxNumberOfBlockTypes = 256;
|
||||
static const size_t kMaxNumberOfBlockTypes = 256;
|
||||
ClusterHistograms(histograms, 1, static_cast<int>(histograms.size()),
|
||||
kMaxNumberOfBlockTypes,
|
||||
&clustered_histograms,
|
||||
&histogram_symbols);
|
||||
for (int i = 0; i < length; ++i) {
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
block_ids[i] = static_cast<uint8_t>(histogram_symbols[block_index[i]]);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "./entropy_encode.h"
|
||||
#include "./fast_log.h"
|
||||
#include "./histogram.h"
|
||||
#include "./port.h"
|
||||
#include "./types.h"
|
||||
|
||||
namespace brotli {
|
||||
@ -111,22 +112,25 @@ void HistogramCombine(HistogramType* out,
|
||||
int* cluster_size,
|
||||
int* symbols,
|
||||
int symbols_size,
|
||||
int max_clusters) {
|
||||
size_t max_clusters) {
|
||||
double cost_diff_threshold = 0.0;
|
||||
int min_cluster_size = 1;
|
||||
size_t min_cluster_size = 1;
|
||||
std::set<int> all_symbols;
|
||||
std::vector<int> clusters;
|
||||
for (int i = 0; i < symbols_size; ++i) {
|
||||
if (all_symbols.find(symbols[i]) == all_symbols.end()) {
|
||||
all_symbols.insert(symbols[i]);
|
||||
if (!clusters.empty()) {
|
||||
BROTLI_DCHECK(clusters.back() < symbols[i]);
|
||||
}
|
||||
clusters.push_back(symbols[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// We maintain a heap of histogram pairs, ordered by the bit cost reduction.
|
||||
std::vector<HistogramPair> pairs;
|
||||
for (int idx1 = 0; idx1 < clusters.size(); ++idx1) {
|
||||
for (int idx2 = idx1 + 1; idx2 < clusters.size(); ++idx2) {
|
||||
for (size_t idx1 = 0; idx1 < clusters.size(); ++idx1) {
|
||||
for (size_t idx2 = idx1 + 1; idx2 < clusters.size(); ++idx2) {
|
||||
CompareAndPushToHeap(out, cluster_size, clusters[idx1], clusters[idx2],
|
||||
&pairs);
|
||||
}
|
||||
@ -149,14 +153,14 @@ void HistogramCombine(HistogramType* out,
|
||||
symbols[i] = best_idx1;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i + 1 < clusters.size(); ++i) {
|
||||
for (size_t i = 0; i + 1 < clusters.size(); ++i) {
|
||||
if (clusters[i] >= best_idx2) {
|
||||
clusters[i] = clusters[i + 1];
|
||||
}
|
||||
}
|
||||
clusters.pop_back();
|
||||
// Invalidate pairs intersecting the just combined best pair.
|
||||
for (int i = 0; i < pairs.size(); ++i) {
|
||||
for (size_t i = 0; i < pairs.size(); ++i) {
|
||||
HistogramPair& p = pairs[i];
|
||||
if (p.idx1 == best_idx1 || p.idx2 == best_idx1 ||
|
||||
p.idx1 == best_idx2 || p.idx2 == best_idx2) {
|
||||
@ -169,7 +173,7 @@ void HistogramCombine(HistogramType* out,
|
||||
pairs.pop_back();
|
||||
}
|
||||
// Push new pairs formed with the combined histogram to the heap.
|
||||
for (int i = 0; i < clusters.size(); ++i) {
|
||||
for (size_t i = 0; i < clusters.size(); ++i) {
|
||||
CompareAndPushToHeap(out, cluster_size, best_idx1, clusters[i], &pairs);
|
||||
}
|
||||
}
|
||||
@ -232,7 +236,7 @@ void HistogramReindex(std::vector<HistogramType>* out,
|
||||
std::vector<HistogramType> tmp(*out);
|
||||
std::map<int, int> new_index;
|
||||
int next_index = 0;
|
||||
for (int i = 0; i < symbols->size(); ++i) {
|
||||
for (size_t i = 0; i < symbols->size(); ++i) {
|
||||
if (new_index.find((*symbols)[i]) == new_index.end()) {
|
||||
new_index[(*symbols)[i]] = next_index;
|
||||
(*out)[next_index] = tmp[(*symbols)[i]];
|
||||
@ -240,7 +244,7 @@ void HistogramReindex(std::vector<HistogramType>* out,
|
||||
}
|
||||
}
|
||||
out->resize(next_index);
|
||||
for (int i = 0; i < symbols->size(); ++i) {
|
||||
for (size_t i = 0; i < symbols->size(); ++i) {
|
||||
(*symbols)[i] = new_index[(*symbols)[i]];
|
||||
}
|
||||
}
|
||||
@ -251,10 +255,11 @@ void HistogramReindex(std::vector<HistogramType>* out,
|
||||
template<typename HistogramType>
|
||||
void ClusterHistograms(const std::vector<HistogramType>& in,
|
||||
int num_contexts, int num_blocks,
|
||||
int max_histograms,
|
||||
size_t max_histograms,
|
||||
std::vector<HistogramType>* out,
|
||||
std::vector<int>* histogram_symbols) {
|
||||
const int in_size = num_contexts * num_blocks;
|
||||
BROTLI_DCHECK(in_size == in.size());
|
||||
std::vector<int> cluster_size(in_size, 1);
|
||||
out->resize(in_size);
|
||||
histogram_symbols->resize(in_size);
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <cstdlib>
|
||||
|
||||
#include "./histogram.h"
|
||||
#include "./port.h"
|
||||
#include "./types.h"
|
||||
|
||||
namespace brotli {
|
||||
@ -141,6 +142,7 @@ void CreateHuffmanTree(const int *data,
|
||||
// Add back the last sentinel node.
|
||||
tree.push_back(sentinel);
|
||||
}
|
||||
BROTLI_DCHECK(tree.size() == 2 * n + 1);
|
||||
SetDepth(tree[2 * n - 1], &tree[0], depth, 0);
|
||||
|
||||
// We need to pack the Huffman tree in tree_limit bits.
|
||||
|
@ -369,7 +369,7 @@ class HashLongestMatch {
|
||||
if (prev_ix >= cur_ix) {
|
||||
continue;
|
||||
}
|
||||
if (PREDICT_FALSE(backward > max_backward)) {
|
||||
if (PREDICT_FALSE(backward > (int)max_backward)) {
|
||||
continue;
|
||||
}
|
||||
prev_ix &= static_cast<uint32_t>(ring_buffer_mask);
|
||||
|
@ -64,7 +64,7 @@ void BuildMetaBlock(const uint8_t* ringbuffer,
|
||||
&distance_histograms);
|
||||
|
||||
// Histogram ids need to fit in one byte.
|
||||
static const int kMaxNumberOfHistograms = 256;
|
||||
static const size_t kMaxNumberOfHistograms = 256;
|
||||
|
||||
mb->literal_histograms = literal_histograms;
|
||||
ClusterHistograms(literal_histograms,
|
||||
|
@ -17,6 +17,7 @@
|
||||
#ifndef BROTLI_ENC_PORT_H_
|
||||
#define BROTLI_ENC_PORT_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "./types.h"
|
||||
|
||||
@ -149,4 +150,10 @@ inline void BROTLI_UNALIGNED_STORE64(void *p, uint64_t v) {
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BROTLI_ENCODE_DEBUG
|
||||
#define BROTLI_DCHECK(x) assert(x)
|
||||
#else
|
||||
#define BROTLI_DCHECK(x)
|
||||
#endif
|
||||
|
||||
#endif // BROTLI_ENC_PORT_H_
|
||||
|
@ -31,8 +31,7 @@ namespace brotli {
|
||||
class RingBuffer {
|
||||
public:
|
||||
RingBuffer(int window_bits, int tail_bits)
|
||||
: window_bits_(window_bits),
|
||||
size_((size_t(1) << window_bits)),
|
||||
: size_((size_t(1) << window_bits)),
|
||||
mask_((size_t(1) << window_bits) - 1),
|
||||
tail_size_(size_t(1) << tail_bits),
|
||||
pos_(0) {
|
||||
@ -92,7 +91,6 @@ class RingBuffer {
|
||||
}
|
||||
|
||||
// Size of the ringbuffer is (1 << window_bits) + tail_size_.
|
||||
const int window_bits_;
|
||||
const size_t size_;
|
||||
const size_t mask_;
|
||||
const size_t tail_size_;
|
||||
|
@ -119,5 +119,4 @@ bool BrotliFileOut::Write(const void* buf, size_t n) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace brotli
|
||||
|
@ -124,7 +124,6 @@ class BrotliFileOut : public BrotliOut {
|
||||
FILE* f_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace brotli
|
||||
|
||||
#endif // BROTLI_ENC_STREAMS_H_
|
||||
|
@ -50,6 +50,7 @@ inline void WriteBits(int n_bits,
|
||||
printf("WriteBits %2d 0x%016llx %10d\n", n_bits, bits, *pos);
|
||||
#endif
|
||||
assert((bits >> n_bits) == 0);
|
||||
assert(n_bits <= 56);
|
||||
#ifdef IS_LITTLE_ENDIAN
|
||||
// This branch of the code can write up to 56 bits at a time,
|
||||
// 7 bits are lost by being perhaps already in *p and at least
|
||||
|
Loading…
Reference in New Issue
Block a user