* fix MSVC warnings
 * cleanups
This commit is contained in:
Eugene Kliuchnikov 2018-06-09 11:17:13 +02:00 committed by GitHub
parent 1e7ea1d8e6
commit 8544ae858d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 38 deletions

View File

@ -628,7 +628,8 @@ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
#define BROTLI_DUMP() (void)(0) #define BROTLI_DUMP() (void)(0)
#endif #endif
#if (BROTLI_MODERN_COMPILER || defined(__llvm__)) && \ /* TODO: add appropriate icc/sunpro/arm/ibm/ti checks. */
#if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \
!defined(BROTLI_BUILD_NO_RBIT) !defined(BROTLI_BUILD_NO_RBIT)
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8) #if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
/* TODO: detect ARMv6T2 and enable this code for it. */ /* TODO: detect ARMv6T2 and enable this code for it. */
@ -680,32 +681,32 @@ static void BrotliDefaultFreeFunc(void* opaque, void* address) {
} }
BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) { BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) {
BROTLI_UNUSED(BrotliSuppressUnusedFunctions); BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
BROTLI_UNUSED(BrotliUnalignedRead16); BROTLI_UNUSED(&BrotliUnalignedRead16);
BROTLI_UNUSED(BrotliUnalignedRead32); BROTLI_UNUSED(&BrotliUnalignedRead32);
BROTLI_UNUSED(BrotliUnalignedRead64); BROTLI_UNUSED(&BrotliUnalignedRead64);
BROTLI_UNUSED(BrotliUnalignedWrite64); BROTLI_UNUSED(&BrotliUnalignedWrite64);
BROTLI_UNUSED(BROTLI_UNALIGNED_LOAD16LE); BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE);
BROTLI_UNUSED(BROTLI_UNALIGNED_LOAD32LE); BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
BROTLI_UNUSED(BROTLI_UNALIGNED_LOAD64LE); BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE);
BROTLI_UNUSED(BROTLI_UNALIGNED_STORE64LE); BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE);
BROTLI_UNUSED(BrotliRBit); BROTLI_UNUSED(&BrotliRBit);
BROTLI_UNUSED(brotli_min_double); BROTLI_UNUSED(&brotli_min_double);
BROTLI_UNUSED(brotli_max_double); BROTLI_UNUSED(&brotli_max_double);
BROTLI_UNUSED(brotli_min_float); BROTLI_UNUSED(&brotli_min_float);
BROTLI_UNUSED(brotli_max_float); BROTLI_UNUSED(&brotli_max_float);
BROTLI_UNUSED(brotli_min_int); BROTLI_UNUSED(&brotli_min_int);
BROTLI_UNUSED(brotli_max_int); BROTLI_UNUSED(&brotli_max_int);
BROTLI_UNUSED(brotli_min_size_t); BROTLI_UNUSED(&brotli_min_size_t);
BROTLI_UNUSED(brotli_max_size_t); BROTLI_UNUSED(&brotli_max_size_t);
BROTLI_UNUSED(brotli_min_uint32_t); BROTLI_UNUSED(&brotli_min_uint32_t);
BROTLI_UNUSED(brotli_max_uint32_t); BROTLI_UNUSED(&brotli_max_uint32_t);
BROTLI_UNUSED(brotli_min_uint8_t); BROTLI_UNUSED(&brotli_min_uint8_t);
BROTLI_UNUSED(brotli_max_uint8_t); BROTLI_UNUSED(&brotli_max_uint8_t);
BROTLI_UNUSED(BrotliDefaultAllocFunc); BROTLI_UNUSED(&BrotliDefaultAllocFunc);
BROTLI_UNUSED(BrotliDefaultFreeFunc); BROTLI_UNUSED(&BrotliDefaultFreeFunc);
#if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG) #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
BROTLI_UNUSED(BrotliDump); BROTLI_UNUSED(&BrotliDump);
#endif #endif
} }

View File

@ -117,7 +117,6 @@ typedef struct BrotliEncoderStateStruct {
static BROTLI_BOOL EnsureInitialized(BrotliEncoderState* s); static BROTLI_BOOL EnsureInitialized(BrotliEncoderState* s);
static size_t InputBlockSize(BrotliEncoderState* s) { static size_t InputBlockSize(BrotliEncoderState* s) {
if (!EnsureInitialized(s)) return 0;
return (size_t)1 << s->params.lgblock; return (size_t)1 << s->params.lgblock;
} }
@ -817,7 +816,6 @@ static void CopyInputToRingBuffer(BrotliEncoderState* s,
const uint8_t* input_buffer) { const uint8_t* input_buffer) {
RingBuffer* ringbuffer_ = &s->ringbuffer_; RingBuffer* ringbuffer_ = &s->ringbuffer_;
MemoryManager* m = &s->memory_manager_; MemoryManager* m = &s->memory_manager_;
if (!EnsureInitialized(s)) return;
RingBufferWrite(m, input_buffer, input_size, ringbuffer_); RingBufferWrite(m, input_buffer, input_size, ringbuffer_);
if (BROTLI_IS_OOM(m)) return; if (BROTLI_IS_OOM(m)) return;
s->input_pos_ += input_size; s->input_pos_ += input_size;
@ -933,7 +931,6 @@ static BROTLI_BOOL EncodeData(
MemoryManager* m = &s->memory_manager_; MemoryManager* m = &s->memory_manager_;
ContextType literal_context_mode; ContextType literal_context_mode;
if (!EnsureInitialized(s)) return BROTLI_FALSE;
data = s->ringbuffer_.buffer_; data = s->ringbuffer_.buffer_;
mask = s->ringbuffer_.mask_; mask = s->ringbuffer_.mask_;

View File

@ -16,11 +16,6 @@
extern "C" { extern "C" {
#endif #endif
/* TODO: use BrotliTransforms.cutOffTransforms instead. */
static const uint8_t kOmitLastNTransforms[10] = {
0, 12, 27, 23, 42, 63, 56, 48, 59, 64,
};
static BROTLI_INLINE uint32_t Hash(const uint8_t* data) { static BROTLI_INLINE uint32_t Hash(const uint8_t* data) {
uint32_t h = BROTLI_UNALIGNED_LOAD32LE(data) * kDictHashMul32; uint32_t h = BROTLI_UNALIGNED_LOAD32LE(data) * kDictHashMul32;
/* The higher bits contain more mixture from the multiplication, /* The higher bits contain more mixture from the multiplication,
@ -121,7 +116,10 @@ BROTLI_BOOL BrotliFindAllStaticDictionaryMatches(
if (l > 9) minlen = BROTLI_MAX(size_t, minlen, l - 9); if (l > 9) minlen = BROTLI_MAX(size_t, minlen, l - 9);
maxlen = BROTLI_MIN(size_t, matchlen, l - 2); maxlen = BROTLI_MIN(size_t, matchlen, l - 2);
for (len = minlen; len <= maxlen; ++len) { for (len = minlen; len <= maxlen; ++len) {
AddMatch(id + kOmitLastNTransforms[l - len] * n, len, l, matches); size_t cut = l - len;
size_t transform_id = (cut << 2) +
(size_t)((dictionary->cutoffTransforms >> (cut * 6)) & 0x3F);
AddMatch(id + transform_id * n, len, l, matches);
has_found_match = BROTLI_TRUE; has_found_match = BROTLI_TRUE;
} }
if (matchlen < l || l + 6 >= max_length) { if (matchlen < l || l + 6 >= max_length) {

View File

@ -53,7 +53,16 @@ public class BrotliInputStream extends InputStream {
if (decoder.closed) { if (decoder.closed) {
throw new IOException("read after close"); throw new IOException("read after close");
} }
if (decoder.decode() == -1) { int decoded;
// Iterate until at leat one byte is decoded, or EOF reached.
while (true) {
decoded = decoder.decode();
if (decoded != 0) {
break;
}
}
if (decoded == -1) {
return -1; return -1;
} }
return decoder.buffer.get() & 0xFF; return decoder.buffer.get() & 0xFF;

View File

@ -15,6 +15,7 @@ import java.util.ArrayList;
* Base class for InputStream / Channel implementations. * Base class for InputStream / Channel implementations.
*/ */
public class Decoder { public class Decoder {
private static final ByteBuffer EMPTY_BUFER = ByteBuffer.allocate(0);
private final ReadableByteChannel source; private final ReadableByteChannel source;
private final DecoderJNI.Wrapper decoder; private final DecoderJNI.Wrapper decoder;
ByteBuffer buffer; ByteBuffer buffer;
@ -87,6 +88,11 @@ public class Decoder {
if (bytesRead == -1) { if (bytesRead == -1) {
fail("unexpected end of input"); fail("unexpected end of input");
} }
if (bytesRead == 0) {
// No input data is currently available.
buffer = EMPTY_BUFER;
return 0;
}
decoder.push(bytesRead); decoder.push(bytesRead);
break; break;

View File

@ -16,7 +16,7 @@
#include <cstdlib> /* exit, EXIT_FAILURE */ #include <cstdlib> /* exit, EXIT_FAILURE */
#include <vector> #include <vector>
#ifndef CHECK #if !defined(CHECK)
#define CHECK(X) if (!(X)) exit(EXIT_FAILURE); #define CHECK(X) if (!(X)) exit(EXIT_FAILURE);
#endif #endif

View File

@ -19,7 +19,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> /* exit, EXIT_FAILURE */ #include <cstdlib> /* exit, EXIT_FAILURE */
#ifndef CHECK #if !defined(CHECK)
#define CHECK(X) if (!(X)) exit(EXIT_FAILURE); #define CHECK(X) if (!(X)) exit(EXIT_FAILURE);
#endif #endif