| OLD | NEW |
| 1 /* Copyright 2013 Google Inc. All Rights Reserved. | 1 /* Copyright 2013 Google Inc. All Rights Reserved. |
| 2 | 2 |
| 3 Distributed under MIT license. | 3 Distributed under MIT license. |
| 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT | 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* Bit reading helpers */ | 7 /* Bit reading helpers */ |
| 8 | 8 |
| 9 #include "./bit_reader.h" | 9 #include "./bit_reader.h" |
| 10 | 10 |
| 11 #include <brotli/types.h> |
| 11 #include "./port.h" | 12 #include "./port.h" |
| 12 #include "./types.h" | |
| 13 | 13 |
| 14 #if defined(__cplusplus) || defined(c_plusplus) | 14 #if defined(__cplusplus) || defined(c_plusplus) |
| 15 extern "C" { | 15 extern "C" { |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 void BrotliInitBitReader(BrotliBitReader* const br) { | 18 void BrotliInitBitReader(BrotliBitReader* const br) { |
| 19 br->val_ = 0; | 19 br->val_ = 0; |
| 20 br->bit_pos_ = sizeof(br->val_) << 3; | 20 br->bit_pos_ = sizeof(br->val_) << 3; |
| 21 } | 21 } |
| 22 | 22 |
| 23 int BrotliWarmupBitReader(BrotliBitReader* const br) { | 23 BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) { |
| 24 size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1; | 24 size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1; |
| 25 /* Fixing alignment after unaligned BrotliFillWindow would result accumulator | 25 /* Fixing alignment after unaligned BrotliFillWindow would result accumulator |
| 26 overflow. If unalignment is caused by BrotliSafeReadBits, then there is | 26 overflow. If unalignment is caused by BrotliSafeReadBits, then there is |
| 27 enough space in accumulator to fix aligment. */ | 27 enough space in accumulator to fix alignment. */ |
| 28 if (!BROTLI_ALIGNED_READ) { | 28 if (!BROTLI_ALIGNED_READ) { |
| 29 aligned_read_mask = 0; | 29 aligned_read_mask = 0; |
| 30 } | 30 } |
| 31 if (BrotliGetAvailableBits(br) == 0) { | 31 if (BrotliGetAvailableBits(br) == 0) { |
| 32 if (!BrotliPullByte(br)) { | 32 if (!BrotliPullByte(br)) { |
| 33 return 0; | 33 return BROTLI_FALSE; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 while ((((size_t)br->next_in) & aligned_read_mask) != 0) { | 37 while ((((size_t)br->next_in) & aligned_read_mask) != 0) { |
| 38 if (!BrotliPullByte(br)) { | 38 if (!BrotliPullByte(br)) { |
| 39 /* If we consumed all the input, we don't care about the alignment. */ | 39 /* If we consumed all the input, we don't care about the alignment. */ |
| 40 return 1; | 40 return BROTLI_TRUE; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 return 1; | 43 return BROTLI_TRUE; |
| 44 } | 44 } |
| 45 | 45 |
| 46 #if defined(__cplusplus) || defined(c_plusplus) | 46 #if defined(__cplusplus) || defined(c_plusplus) |
| 47 } /* extern "C" */ | 47 } /* extern "C" */ |
| 48 #endif | 48 #endif |
| OLD | NEW |