mirror of
https://github.com/google/brotli.git
synced 2024-11-09 13:40:06 +00:00
parent
1e7ea1d8e6
commit
8544ae858d
@ -628,7 +628,8 @@ static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) {
|
||||
#define BROTLI_DUMP() (void)(0)
|
||||
#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)
|
||||
#if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
|
||||
/* 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(BrotliSuppressUnusedFunctions);
|
||||
BROTLI_UNUSED(BrotliUnalignedRead16);
|
||||
BROTLI_UNUSED(BrotliUnalignedRead32);
|
||||
BROTLI_UNUSED(BrotliUnalignedRead64);
|
||||
BROTLI_UNUSED(BrotliUnalignedWrite64);
|
||||
BROTLI_UNUSED(BROTLI_UNALIGNED_LOAD16LE);
|
||||
BROTLI_UNUSED(BROTLI_UNALIGNED_LOAD32LE);
|
||||
BROTLI_UNUSED(BROTLI_UNALIGNED_LOAD64LE);
|
||||
BROTLI_UNUSED(BROTLI_UNALIGNED_STORE64LE);
|
||||
BROTLI_UNUSED(BrotliRBit);
|
||||
BROTLI_UNUSED(brotli_min_double);
|
||||
BROTLI_UNUSED(brotli_max_double);
|
||||
BROTLI_UNUSED(brotli_min_float);
|
||||
BROTLI_UNUSED(brotli_max_float);
|
||||
BROTLI_UNUSED(brotli_min_int);
|
||||
BROTLI_UNUSED(brotli_max_int);
|
||||
BROTLI_UNUSED(brotli_min_size_t);
|
||||
BROTLI_UNUSED(brotli_max_size_t);
|
||||
BROTLI_UNUSED(brotli_min_uint32_t);
|
||||
BROTLI_UNUSED(brotli_max_uint32_t);
|
||||
BROTLI_UNUSED(brotli_min_uint8_t);
|
||||
BROTLI_UNUSED(brotli_max_uint8_t);
|
||||
BROTLI_UNUSED(BrotliDefaultAllocFunc);
|
||||
BROTLI_UNUSED(BrotliDefaultFreeFunc);
|
||||
BROTLI_UNUSED(&BrotliSuppressUnusedFunctions);
|
||||
BROTLI_UNUSED(&BrotliUnalignedRead16);
|
||||
BROTLI_UNUSED(&BrotliUnalignedRead32);
|
||||
BROTLI_UNUSED(&BrotliUnalignedRead64);
|
||||
BROTLI_UNUSED(&BrotliUnalignedWrite64);
|
||||
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE);
|
||||
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE);
|
||||
BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE);
|
||||
BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE);
|
||||
BROTLI_UNUSED(&BrotliRBit);
|
||||
BROTLI_UNUSED(&brotli_min_double);
|
||||
BROTLI_UNUSED(&brotli_max_double);
|
||||
BROTLI_UNUSED(&brotli_min_float);
|
||||
BROTLI_UNUSED(&brotli_max_float);
|
||||
BROTLI_UNUSED(&brotli_min_int);
|
||||
BROTLI_UNUSED(&brotli_max_int);
|
||||
BROTLI_UNUSED(&brotli_min_size_t);
|
||||
BROTLI_UNUSED(&brotli_max_size_t);
|
||||
BROTLI_UNUSED(&brotli_min_uint32_t);
|
||||
BROTLI_UNUSED(&brotli_max_uint32_t);
|
||||
BROTLI_UNUSED(&brotli_min_uint8_t);
|
||||
BROTLI_UNUSED(&brotli_max_uint8_t);
|
||||
BROTLI_UNUSED(&BrotliDefaultAllocFunc);
|
||||
BROTLI_UNUSED(&BrotliDefaultFreeFunc);
|
||||
#if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
|
||||
BROTLI_UNUSED(BrotliDump);
|
||||
BROTLI_UNUSED(&BrotliDump);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,6 @@ typedef struct BrotliEncoderStateStruct {
|
||||
static BROTLI_BOOL EnsureInitialized(BrotliEncoderState* s);
|
||||
|
||||
static size_t InputBlockSize(BrotliEncoderState* s) {
|
||||
if (!EnsureInitialized(s)) return 0;
|
||||
return (size_t)1 << s->params.lgblock;
|
||||
}
|
||||
|
||||
@ -817,7 +816,6 @@ static void CopyInputToRingBuffer(BrotliEncoderState* s,
|
||||
const uint8_t* input_buffer) {
|
||||
RingBuffer* ringbuffer_ = &s->ringbuffer_;
|
||||
MemoryManager* m = &s->memory_manager_;
|
||||
if (!EnsureInitialized(s)) return;
|
||||
RingBufferWrite(m, input_buffer, input_size, ringbuffer_);
|
||||
if (BROTLI_IS_OOM(m)) return;
|
||||
s->input_pos_ += input_size;
|
||||
@ -933,7 +931,6 @@ static BROTLI_BOOL EncodeData(
|
||||
MemoryManager* m = &s->memory_manager_;
|
||||
ContextType literal_context_mode;
|
||||
|
||||
if (!EnsureInitialized(s)) return BROTLI_FALSE;
|
||||
data = s->ringbuffer_.buffer_;
|
||||
mask = s->ringbuffer_.mask_;
|
||||
|
||||
|
@ -16,11 +16,6 @@
|
||||
extern "C" {
|
||||
#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) {
|
||||
uint32_t h = BROTLI_UNALIGNED_LOAD32LE(data) * kDictHashMul32;
|
||||
/* 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);
|
||||
maxlen = BROTLI_MIN(size_t, matchlen, l - 2);
|
||||
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;
|
||||
}
|
||||
if (matchlen < l || l + 6 >= max_length) {
|
||||
|
@ -53,7 +53,16 @@ public class BrotliInputStream extends InputStream {
|
||||
if (decoder.closed) {
|
||||
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 decoder.buffer.get() & 0xFF;
|
||||
|
@ -15,6 +15,7 @@ import java.util.ArrayList;
|
||||
* Base class for InputStream / Channel implementations.
|
||||
*/
|
||||
public class Decoder {
|
||||
private static final ByteBuffer EMPTY_BUFER = ByteBuffer.allocate(0);
|
||||
private final ReadableByteChannel source;
|
||||
private final DecoderJNI.Wrapper decoder;
|
||||
ByteBuffer buffer;
|
||||
@ -87,6 +88,11 @@ public class Decoder {
|
||||
if (bytesRead == -1) {
|
||||
fail("unexpected end of input");
|
||||
}
|
||||
if (bytesRead == 0) {
|
||||
// No input data is currently available.
|
||||
buffer = EMPTY_BUFER;
|
||||
return 0;
|
||||
}
|
||||
decoder.push(bytesRead);
|
||||
break;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <cstdlib> /* exit, EXIT_FAILURE */
|
||||
#include <vector>
|
||||
|
||||
#ifndef CHECK
|
||||
#if !defined(CHECK)
|
||||
#define CHECK(X) if (!(X)) exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib> /* exit, EXIT_FAILURE */
|
||||
|
||||
#ifndef CHECK
|
||||
#if !defined(CHECK)
|
||||
#define CHECK(X) if (!(X)) exit(EXIT_FAILURE);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user