brotli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/ext/brotli/brotli.cc +114 -24
  3. data/ext/brotli/brotli.h +0 -1
  4. data/ext/brotli/extconf.rb +30 -23
  5. data/lib/brotli/version.rb +1 -1
  6. data/vendor/brotli/LICENSE +1 -1
  7. data/vendor/brotli/dec/Makefile +1 -1
  8. data/vendor/brotli/dec/bit_reader.c +3 -3
  9. data/vendor/brotli/dec/bit_reader.h +25 -27
  10. data/vendor/brotli/dec/context.h +4 -4
  11. data/vendor/brotli/dec/decode.c +410 -486
  12. data/vendor/brotli/dec/decode.h +101 -105
  13. data/vendor/brotli/dec/dictionary.c +1 -1
  14. data/vendor/brotli/dec/dictionary.h +7 -8
  15. data/vendor/brotli/dec/huffman.c +103 -105
  16. data/vendor/brotli/dec/huffman.h +18 -18
  17. data/vendor/brotli/dec/port.h +52 -40
  18. data/vendor/brotli/dec/prefix.h +2 -0
  19. data/vendor/brotli/dec/state.c +13 -19
  20. data/vendor/brotli/dec/state.h +25 -39
  21. data/vendor/brotli/dec/transform.h +38 -44
  22. data/vendor/brotli/dec/types.h +2 -2
  23. data/vendor/brotli/enc/Makefile +1 -1
  24. data/vendor/brotli/enc/backward_references.cc +455 -359
  25. data/vendor/brotli/enc/backward_references.h +79 -3
  26. data/vendor/brotli/enc/bit_cost.h +54 -32
  27. data/vendor/brotli/enc/block_splitter.cc +285 -193
  28. data/vendor/brotli/enc/block_splitter.h +4 -12
  29. data/vendor/brotli/enc/brotli_bit_stream.cc +623 -324
  30. data/vendor/brotli/enc/brotli_bit_stream.h +76 -37
  31. data/vendor/brotli/enc/cluster.h +161 -120
  32. data/vendor/brotli/enc/command.h +60 -37
  33. data/vendor/brotli/enc/compress_fragment.cc +701 -0
  34. data/vendor/brotli/enc/compress_fragment.h +47 -0
  35. data/vendor/brotli/enc/compress_fragment_two_pass.cc +524 -0
  36. data/vendor/brotli/enc/compress_fragment_two_pass.h +40 -0
  37. data/vendor/brotli/enc/compressor.h +15 -0
  38. data/vendor/brotli/enc/context.h +1 -1
  39. data/vendor/brotli/enc/dictionary.h +2 -2
  40. data/vendor/brotli/enc/encode.cc +819 -286
  41. data/vendor/brotli/enc/encode.h +38 -15
  42. data/vendor/brotli/enc/encode_parallel.cc +40 -42
  43. data/vendor/brotli/enc/entropy_encode.cc +144 -147
  44. data/vendor/brotli/enc/entropy_encode.h +32 -8
  45. data/vendor/brotli/enc/entropy_encode_static.h +572 -0
  46. data/vendor/brotli/enc/fast_log.h +7 -40
  47. data/vendor/brotli/enc/find_match_length.h +9 -9
  48. data/vendor/brotli/enc/hash.h +462 -154
  49. data/vendor/brotli/enc/histogram.cc +6 -6
  50. data/vendor/brotli/enc/histogram.h +13 -13
  51. data/vendor/brotli/enc/literal_cost.cc +45 -45
  52. data/vendor/brotli/enc/metablock.cc +92 -89
  53. data/vendor/brotli/enc/metablock.h +12 -12
  54. data/vendor/brotli/enc/port.h +7 -16
  55. data/vendor/brotli/enc/prefix.h +23 -22
  56. data/vendor/brotli/enc/ringbuffer.h +75 -29
  57. data/vendor/brotli/enc/static_dict.cc +56 -48
  58. data/vendor/brotli/enc/static_dict.h +5 -5
  59. data/vendor/brotli/enc/streams.cc +1 -1
  60. data/vendor/brotli/enc/streams.h +5 -5
  61. data/vendor/brotli/enc/transform.h +40 -35
  62. data/vendor/brotli/enc/types.h +2 -0
  63. data/vendor/brotli/enc/utf8_util.cc +3 -2
  64. data/vendor/brotli/enc/write_bits.h +6 -6
  65. metadata +9 -5
  66. data/vendor/brotli/dec/streams.c +0 -102
  67. data/vendor/brotli/dec/streams.h +0 -95
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a84cc7be2ff8f77b71c2a257ca25211a9c3ca23
4
- data.tar.gz: bb07eb56c3ae937a98b6cd6c80589ca773562a0f
3
+ metadata.gz: 7de822751d5b3f546404565d93bc0679b0742545
4
+ data.tar.gz: 47aa47a72c5db72815ab325e832bb38e2b37934f
5
5
  SHA512:
6
- metadata.gz: 5fe7de8328e763d815eeaf6c031998fecf3a8e1bf85130808207de71a39311eb7c5cae3abc9f0f7fd2a31c5cc93b50184b1c097f76bf9e3a35a669d959647e72
7
- data.tar.gz: f4814c98c1066b5aa9f06125d19ccbfe6ff3828abacce332baa39da79bc3eb27bf864d157e33dcc5c30ceec0c3c060b438ffb328d97c0f6d9aab120460ab3b38
6
+ metadata.gz: c33554e3f20e4fa992bb0a0730f283695c6bf83df73fb194db522de443a3b652eae7dd84d2671a2ddb8d3452c32e1f6ffa71332b4732c02094ca0fc2963d6f36
7
+ data.tar.gz: 3a07f28a8953211b2d7e6884323e8e48ef568cf1d6242de575d0e12daecb9f002921613f213b5ca6242058528eb1d9a78bcb84a4f22feaa9d197845d3a58ea60
data/ext/brotli/brotli.cc CHANGED
@@ -1,14 +1,22 @@
1
1
  #include "brotli.h"
2
2
 
3
+ #define CSTR2SYM(x) ID2SYM(rb_intern(x))
4
+
3
5
  static VALUE rb_mBrotli;
4
6
  static VALUE rb_eBrotli;
5
7
 
6
- static int
7
- brotli_inflate_cb(void* data, const uint8_t* buf, size_t count)
8
+ static void*
9
+ brotli_alloc(void* opaque, size_t size)
10
+ {
11
+ return xmalloc(size);
12
+ }
13
+
14
+ static void
15
+ brotli_free(void* opaque, void* address)
8
16
  {
9
- VALUE dst = (VALUE)data;
10
- rb_str_cat(dst, (const char*)buf, count);
11
- return count;
17
+ if (address) {
18
+ xfree(address);
19
+ }
12
20
  }
13
21
 
14
22
  static VALUE
@@ -16,34 +24,116 @@ brotli_inflate(VALUE self, VALUE str)
16
24
  {
17
25
  StringValue(str);
18
26
 
19
- VALUE dst = rb_str_buf_new(RSTRING_LEN(str));
20
- BrotliMemInput memin;
21
- BrotliInput in = BrotliInitMemInput((uint8_t*)RSTRING_PTR(str), (size_t)RSTRING_LEN(str), &memin);
22
- BrotliOutput out;
23
- out.cb_ = &brotli_inflate_cb;
24
- out.data_ = (void*)dst;
25
-
26
- switch(BrotliDecompress(in, out)) {
27
- case BROTLI_RESULT_SUCCESS:
28
- return dst;
29
- case BROTLI_RESULT_ERROR:
30
- rb_raise(rb_eBrotli, "ERROR");
31
- break;
32
- case BROTLI_RESULT_NEEDS_MORE_INPUT:
27
+ uint8_t output[BUFSIZ];
28
+ BrotliResult result = BROTLI_RESULT_ERROR;
29
+ size_t available_in = (size_t)RSTRING_LEN(str);
30
+ const uint8_t* next_in = (uint8_t*)RSTRING_PTR(str);
31
+ size_t available_out = BUFSIZ;
32
+ uint8_t* next_out = output;
33
+ size_t total_out = 0;
34
+ VALUE value = rb_str_buf_new(available_in);
35
+
36
+ BrotliState* s = BrotliCreateState(brotli_alloc, brotli_free, NULL);
37
+
38
+ for (;;) {
39
+ result = BrotliDecompressStream(&available_in,
40
+ &next_in,
41
+ &available_out,
42
+ &next_out,
43
+ &total_out,
44
+ s);
45
+ // success, error or needs more input
46
+ if (result != BROTLI_RESULT_NEEDS_MORE_OUTPUT) {
47
+ break;
48
+ }
49
+ rb_str_buf_cat(value, (const char*)output, BUFSIZ);
50
+ available_out = BUFSIZ;
51
+ next_out = output;
52
+ }
53
+
54
+ if (next_out != output) {
55
+ rb_str_buf_cat(value, (const char*)output, next_out - output);
56
+ }
57
+
58
+ if (result == BROTLI_RESULT_ERROR) {
59
+ const char* error = BrotliErrorString(BrotliGetErrorCode(s));
60
+ BrotliDestroyState(s);
61
+ rb_raise(rb_eBrotli, "%s", error);
62
+ }
63
+
64
+ BrotliDestroyState(s);
65
+
66
+ if (result == BROTLI_RESULT_NEEDS_MORE_INPUT) {
33
67
  rb_raise(rb_eBrotli, "Needs more input");
34
- break;
35
- case BROTLI_RESULT_NEEDS_MORE_OUTPUT:
68
+ } else if (result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) {
36
69
  rb_raise(rb_eBrotli, "Needs more output");
37
- break;
70
+ }
71
+
72
+ return value;
73
+ }
74
+
75
+ static void
76
+ brotli_deflate_parse_options(brotli::BrotliParams& params, VALUE opts)
77
+ {
78
+ VALUE tmp;
79
+
80
+ tmp = rb_hash_aref(opts, CSTR2SYM("mode"));
81
+ if (!NIL_P(tmp)) {
82
+ if (tmp == CSTR2SYM("generic")) {
83
+ params.mode = brotli::BrotliParams::MODE_GENERIC;
84
+ } else if (tmp == CSTR2SYM("text")) {
85
+ params.mode = brotli::BrotliParams::MODE_TEXT;
86
+ } else if (tmp == CSTR2SYM("font")) {
87
+ params.mode = brotli::BrotliParams::MODE_FONT;
88
+ } else {
89
+ rb_raise(rb_eArgError, "invalid mode");
90
+ }
91
+ }
92
+
93
+ tmp = rb_hash_aref(opts, CSTR2SYM("quality"));
94
+ if (!NIL_P(tmp)) {
95
+ int value = NUM2INT(tmp);
96
+ if (0 <= value && value <= 11) {
97
+ params.quality = value;
98
+ } else {
99
+ rb_raise(rb_eArgError, "invalid quality value. Should be 0 to 11.");
100
+ }
101
+ }
102
+
103
+ tmp = rb_hash_aref(opts, CSTR2SYM("lgwin"));
104
+ if (!NIL_P(tmp)) {
105
+ int value = NUM2INT(tmp);
106
+ if (10 <= value && value <= 24) {
107
+ params.lgwin = value;
108
+ } else {
109
+ rb_raise(rb_eArgError, "invalid lgwin value. Should be 10 to 24.");
110
+ }
111
+ }
112
+
113
+ tmp = rb_hash_aref(opts, CSTR2SYM("lgblock"));
114
+ if (!NIL_P(tmp)) {
115
+ int value = NUM2INT(tmp);
116
+ if ((value == 0) || (16 <= value && value <= 24)) {
117
+ params.lgblock = value;
118
+ } else {
119
+ rb_raise(rb_eArgError, "invalid lgblock value. Should be 0 or 16 to 24.");
120
+ }
38
121
  }
39
122
  }
40
123
 
41
124
  static VALUE
42
- brotli_deflate(VALUE self, VALUE str)
125
+ brotli_deflate(int argc, VALUE *argv, VALUE self)
43
126
  {
127
+ VALUE str, opts;
128
+ rb_scan_args(argc, argv, "11", &str, &opts);
129
+
44
130
  StringValue(str);
45
131
 
46
132
  brotli::BrotliParams params;
133
+ if (!NIL_P(opts)) {
134
+ brotli_deflate_parse_options(params, opts);
135
+ }
136
+
47
137
  brotli::BrotliMemIn in(RSTRING_PTR(str), RSTRING_LEN(str));
48
138
  std::string buf;
49
139
  buf.reserve(RSTRING_LEN(str) * 2 + 1);
@@ -61,7 +151,7 @@ Init_brotli(void)
61
151
  {
62
152
  rb_mBrotli = rb_define_module("Brotli");
63
153
  rb_eBrotli = rb_define_class_under(rb_mBrotli, "Error", rb_eStandardError);
64
- rb_define_singleton_method(rb_mBrotli, "deflate", RUBY_METHOD_FUNC(brotli_deflate), 1);
154
+ rb_define_singleton_method(rb_mBrotli, "deflate", RUBY_METHOD_FUNC(brotli_deflate), -1);
65
155
  rb_define_singleton_method(rb_mBrotli, "inflate", RUBY_METHOD_FUNC(brotli_inflate), 1);
66
156
  }
67
157
  }
data/ext/brotli/brotli.h CHANGED
@@ -4,6 +4,5 @@
4
4
  #include "ruby.h"
5
5
  #include "enc/encode.h"
6
6
  #include "dec/decode.h"
7
- #include "dec/streams.h"
8
7
 
9
8
  #endif /* BROTLI_H */
@@ -13,61 +13,68 @@ FileUtils.mkdir_p File.join(__dir__, 'dec')
13
13
  srcs = []
14
14
  objs = []
15
15
  [
16
- 'enc/backward_references.cc',
17
- 'enc/block_splitter.cc',
18
- 'enc/brotli_bit_stream.cc',
19
- 'enc/encode.cc',
20
- 'enc/entropy_encode.cc',
21
- 'enc/histogram.cc',
22
- 'enc/literal_cost.cc',
23
- 'enc/metablock.cc',
24
- 'enc/static_dict.cc',
25
- 'enc/streams.cc',
26
- 'enc/utf8_util.cc',
27
16
  'dec/bit_reader.c',
17
+ 'dec/bit_reader.h',
18
+ 'dec/context.h',
28
19
  'dec/decode.c',
20
+ 'dec/decode.h',
29
21
  'dec/dictionary.c',
22
+ 'dec/dictionary.h',
30
23
  'dec/huffman.c',
31
- 'dec/streams.c',
24
+ 'dec/huffman.h',
25
+ 'dec/port.h',
26
+ 'dec/prefix.h',
32
27
  'dec/state.c',
28
+ 'dec/state.h',
29
+ 'dec/transform.h',
30
+ 'dec/types.h',
31
+ 'enc/backward_references.cc',
33
32
  'enc/backward_references.h',
34
33
  'enc/bit_cost.h',
34
+ 'enc/block_splitter.cc',
35
35
  'enc/block_splitter.h',
36
+ 'enc/brotli_bit_stream.cc',
36
37
  'enc/brotli_bit_stream.h',
37
38
  'enc/cluster.h',
38
39
  'enc/command.h',
40
+ 'enc/compress_fragment.cc',
41
+ 'enc/compress_fragment.h',
42
+ 'enc/compress_fragment_two_pass.cc',
43
+ 'enc/compress_fragment_two_pass.h',
44
+ 'enc/compressor.h',
39
45
  'enc/context.h',
46
+ #'enc/dictionary.cc',
40
47
  'enc/dictionary.h',
41
48
  'enc/dictionary_hash.h',
49
+ 'enc/encode.cc',
42
50
  'enc/encode.h',
51
+ 'enc/encode_parallel.cc',
52
+ 'enc/encode_parallel.h',
53
+ 'enc/entropy_encode.cc',
43
54
  'enc/entropy_encode.h',
55
+ 'enc/entropy_encode_static.h',
44
56
  'enc/fast_log.h',
45
57
  'enc/find_match_length.h',
46
58
  'enc/hash.h',
59
+ 'enc/histogram.cc',
47
60
  'enc/histogram.h',
61
+ 'enc/literal_cost.cc',
48
62
  'enc/literal_cost.h',
63
+ 'enc/metablock.cc',
49
64
  'enc/metablock.h',
50
65
  'enc/port.h',
51
66
  'enc/prefix.h',
52
67
  'enc/ringbuffer.h',
68
+ 'enc/static_dict.cc',
53
69
  'enc/static_dict.h',
54
70
  'enc/static_dict_lut.h',
71
+ 'enc/streams.cc',
55
72
  'enc/streams.h',
56
73
  'enc/transform.h',
57
74
  'enc/types.h',
75
+ 'enc/utf8_util.cc',
58
76
  'enc/utf8_util.h',
59
77
  'enc/write_bits.h',
60
- 'dec/bit_reader.h',
61
- 'dec/context.h',
62
- 'dec/decode.h',
63
- 'dec/dictionary.h',
64
- 'dec/huffman.h',
65
- 'dec/prefix.h',
66
- 'dec/port.h',
67
- 'dec/streams.h',
68
- 'dec/transform.h',
69
- 'dec/types.h',
70
- 'dec/state.h',
71
78
  ].each do |file|
72
79
  FileUtils.cp(File.expand_path(File.join(__dir__, '..', '..', 'vendor', 'brotli', file)),
73
80
  File.expand_path(File.join(__dir__, file)),
@@ -1,3 +1,3 @@
1
1
  module Brotli
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009, 2010, 2013-2015 by the Brotli Authors.
1
+ Copyright (c) 2009, 2010, 2013-2016 by the Brotli Authors.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -4,7 +4,7 @@ include ../shared.mk
4
4
 
5
5
  CFLAGS += -Wall
6
6
 
7
- OBJS = bit_reader.o decode.o dictionary.o huffman.o state.o streams.o
7
+ OBJS = bit_reader.o decode.o dictionary.o huffman.o state.o
8
8
 
9
9
  all : $(OBJS)
10
10
 
@@ -6,10 +6,10 @@
6
6
 
7
7
  /* Bit reading helpers */
8
8
 
9
- #include <stdlib.h>
10
-
11
9
  #include "./bit_reader.h"
10
+
12
11
  #include "./port.h"
12
+ #include "./types.h"
13
13
 
14
14
  #if defined(__cplusplus) || defined(c_plusplus)
15
15
  extern "C" {
@@ -44,5 +44,5 @@ int BrotliWarmupBitReader(BrotliBitReader* const br) {
44
44
  }
45
45
 
46
46
  #if defined(__cplusplus) || defined(c_plusplus)
47
- } /* extern "C" */
47
+ } /* extern "C" */
48
48
  #endif
@@ -9,8 +9,8 @@
9
9
  #ifndef BROTLI_DEC_BIT_READER_H_
10
10
  #define BROTLI_DEC_BIT_READER_H_
11
11
 
12
- #include <stdio.h>
13
- #include <string.h>
12
+ #include <string.h> /* memcpy */
13
+
14
14
  #include "./port.h"
15
15
  #include "./types.h"
16
16
 
@@ -48,27 +48,27 @@ static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
48
48
  }
49
49
 
50
50
  typedef struct {
51
- reg_t val_; /* pre-fetched bits */
52
- uint32_t bit_pos_; /* current bit-reading position in val_ */
53
- const uint8_t* next_in; /* the byte we're reading from */
54
- size_t avail_in;
51
+ reg_t val_; /* pre-fetched bits */
52
+ uint32_t bit_pos_; /* current bit-reading position in val_ */
53
+ const uint8_t* next_in; /* the byte we're reading from */
54
+ size_t avail_in;
55
55
  } BrotliBitReader;
56
56
 
57
57
  typedef struct {
58
- reg_t val_;
58
+ reg_t val_;
59
59
  uint32_t bit_pos_;
60
60
  const uint8_t* next_in;
61
- size_t avail_in;
61
+ size_t avail_in;
62
62
  } BrotliBitReaderState;
63
63
 
64
64
  /* Initializes the bitreader fields. */
65
- void BrotliInitBitReader(BrotliBitReader* const br);
65
+ BROTLI_INTERNAL void BrotliInitBitReader(BrotliBitReader* const br);
66
66
 
67
67
  /* Ensures that accumulator is not empty. May consume one byte of input.
68
68
  Returns 0 if data is required but there is no input available.
69
- For BROTLI_BUILD_PORTABLE this function also prepares bit reader for aligned
69
+ For BROTLI_ALIGNED_READ this function also prepares bit reader for aligned
70
70
  reading. */
71
- int BrotliWarmupBitReader(BrotliBitReader* const br);
71
+ BROTLI_INTERNAL int BrotliWarmupBitReader(BrotliBitReader* const br);
72
72
 
73
73
  static BROTLI_INLINE void BrotliBitReaderSaveState(
74
74
  BrotliBitReader* const from, BrotliBitReaderState* to) {
@@ -109,9 +109,7 @@ static BROTLI_INLINE uint16_t BrotliLoad16LE(const uint8_t* in) {
109
109
  return *((const uint16_t*)in);
110
110
  } else if (BROTLI_BIG_ENDIAN) {
111
111
  uint16_t value = *((const uint16_t*)in);
112
- return (uint16_t)(
113
- ((value & 0xFFU) << 8) |
114
- ((value & 0xFF00U) >> 8));
112
+ return (uint16_t)(((value & 0xFFU) << 8) | ((value & 0xFF00U) >> 8));
115
113
  } else {
116
114
  return (uint16_t)(in[0] | (in[1] << 8));
117
115
  }
@@ -228,9 +226,9 @@ static BROTLI_INLINE int BrotliPullByte(BrotliBitReader* const br) {
228
226
  }
229
227
  br->val_ >>= 8;
230
228
  #if (BROTLI_64_BITS)
231
- br->val_ |= ((uint64_t)*br->next_in) << 56;
229
+ br->val_ |= ((uint64_t)*br->next_in) << 56;
232
230
  #else
233
- br->val_ |= ((uint32_t)*br->next_in) << 24;
231
+ br->val_ |= ((uint32_t)*br->next_in) << 24;
234
232
  #endif
235
233
  br->bit_pos_ -= 8;
236
234
  --br->avail_in;
@@ -262,7 +260,7 @@ static BROTLI_INLINE uint32_t BrotliGetBits(
262
260
  /* Tries to peek the specified amount of bits. Returns 0, if there is not
263
261
  enough input. */
264
262
  static BROTLI_INLINE int BrotliSafeGetBits(
265
- BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
263
+ BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
266
264
  while (BrotliGetAvailableBits(br) < n_bits) {
267
265
  if (!BrotliPullByte(br)) {
268
266
  return 0;
@@ -283,7 +281,11 @@ static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
283
281
  uint32_t unused_bits = unused_bytes << 3;
284
282
  br->avail_in += unused_bytes;
285
283
  br->next_in -= unused_bytes;
286
- br->val_ <<= unused_bits;
284
+ if (unused_bits == sizeof(br->val_) << 3) {
285
+ br->val_ = 0;
286
+ } else {
287
+ br->val_ <<= unused_bits;
288
+ }
287
289
  br->bit_pos_ += unused_bits;
288
290
  }
289
291
 
@@ -292,10 +294,8 @@ static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
292
294
  static BROTLI_INLINE void BrotliTakeBits(
293
295
  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
294
296
  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
295
- #ifdef BROTLI_DECODE_DEBUG
296
- printf("[BrotliReadBits] %d %d %d val: %6x\n",
297
- (int)br->avail_in, (int)br->bit_pos_, n_bits, (int)*val);
298
- #endif
297
+ BROTLI_LOG(("[BrotliReadBits] %d %d %d val: %6x\n",
298
+ (int)br->avail_in, (int)br->bit_pos_, n_bits, (int)*val));
299
299
  BrotliDropBits(br, n_bits);
300
300
  }
301
301
 
@@ -322,7 +322,7 @@ static BROTLI_INLINE uint32_t BrotliReadBits(
322
322
  /* Tries to read the specified amount of bits. Returns 0, if there is not
323
323
  enough input. n_bits MUST be positive. */
324
324
  static BROTLI_INLINE int BrotliSafeReadBits(
325
- BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
325
+ BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
326
326
  while (BrotliGetAvailableBits(br) < n_bits) {
327
327
  if (!BrotliPullByte(br)) {
328
328
  return 0;
@@ -349,9 +349,7 @@ static BROTLI_INLINE int BrotliJumpToByteBoundary(BrotliBitReader* br) {
349
349
  static BROTLI_INLINE int BrotliPeekByte(BrotliBitReader* br, size_t offset) {
350
350
  uint32_t available_bits = BrotliGetAvailableBits(br);
351
351
  size_t bytes_left = available_bits >> 3;
352
- if (available_bits & 7) {
353
- return -1;
354
- }
352
+ BROTLI_DCHECK((available_bits & 7) == 0);
355
353
  if (offset < bytes_left) {
356
354
  return (BrotliGetBitsUnmasked(br) >> (unsigned)(offset << 3)) & 0xFF;
357
355
  }
@@ -379,7 +377,7 @@ static BROTLI_INLINE void BrotliCopyBytes(uint8_t* dest,
379
377
  }
380
378
 
381
379
  #if defined(__cplusplus) || defined(c_plusplus)
382
- } /* extern "C" */
380
+ } /* extern "C" */
383
381
  #endif
384
382
 
385
383
  #endif /* BROTLI_DEC_BIT_READER_H_ */
@@ -102,10 +102,10 @@
102
102
  #include "./types.h"
103
103
 
104
104
  enum ContextType {
105
- CONTEXT_LSB6 = 0,
106
- CONTEXT_MSB6 = 1,
107
- CONTEXT_UTF8 = 2,
108
- CONTEXT_SIGNED = 3
105
+ CONTEXT_LSB6 = 0,
106
+ CONTEXT_MSB6 = 1,
107
+ CONTEXT_UTF8 = 2,
108
+ CONTEXT_SIGNED = 3
109
109
  };
110
110
 
111
111
  /* Common context lookup table for all context modes. */