Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Unified Diff: third_party/brotli/enc/write_bits.h

Issue 2537133002: Update brotli to v1.0.0-snapshot. (Closed)
Patch Set: Fixed typo Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/brotli/enc/utf8_util.cc ('k') | third_party/brotli/include/brotli/decode.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/brotli/enc/write_bits.h
diff --git a/third_party/brotli/enc/write_bits.h b/third_party/brotli/enc/write_bits.h
index b605203a3614167de75e516169f90f444eb1da86..3999c917806ec23baa8fddcde0f7cf7ee6b10dee 100644
--- a/third_party/brotli/enc/write_bits.h
+++ b/third_party/brotli/enc/write_bits.h
@@ -4,74 +4,78 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
-// Write bits into a byte array.
+/* Write bits into a byte array. */
#ifndef BROTLI_ENC_WRITE_BITS_H_
#define BROTLI_ENC_WRITE_BITS_H_
#include <assert.h>
-#include <stdio.h>
+#include <stdio.h> /* printf */
+#include <brotli/types.h>
#include "./port.h"
-#include "./types.h"
-
-namespace brotli {
-
-//#define BIT_WRITER_DEBUG
-
-// This function writes bits into bytes in increasing addresses, and within
-// a byte least-significant-bit first.
-//
-// The function can write up to 56 bits in one go with WriteBits
-// Example: let's assume that 3 bits (Rs below) have been written already:
-//
-// BYTE-0 BYTE+1 BYTE+2
-//
-// 0000 0RRR 0000 0000 0000 0000
-//
-// Now, we could write 5 or less bits in MSB by just sifting by 3
-// and OR'ing to BYTE-0.
-//
-// For n bits, we take the last 5 bits, OR that with high bits in BYTE-0,
-// and locate the rest in BYTE+1, BYTE+2, etc.
-inline void WriteBits(size_t n_bits,
- uint64_t bits,
- size_t * __restrict pos,
- uint8_t * __restrict array) {
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+/*#define BIT_WRITER_DEBUG */
+
+/* This function writes bits into bytes in increasing addresses, and within
+ a byte least-significant-bit first.
+
+ The function can write up to 56 bits in one go with WriteBits
+ Example: let's assume that 3 bits (Rs below) have been written already:
+
+ BYTE-0 BYTE+1 BYTE+2
+
+ 0000 0RRR 0000 0000 0000 0000
+
+ Now, we could write 5 or less bits in MSB by just sifting by 3
+ and OR'ing to BYTE-0.
+
+ For n bits, we take the last 5 bits, OR that with high bits in BYTE-0,
+ and locate the rest in BYTE+1, BYTE+2, etc. */
+static BROTLI_INLINE void BrotliWriteBits(size_t n_bits,
+ uint64_t bits,
+ size_t * BROTLI_RESTRICT pos,
+ uint8_t * BROTLI_RESTRICT array) {
+#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
+ 1 bit is needed to initialize the bit-stream ahead (i.e. if 7
+ bits are in *p and we write 57 bits, then the next write will
+ access a byte that was never initialized). */
+ uint8_t *p = &array[*pos >> 3];
+ uint64_t v = *p;
#ifdef BIT_WRITER_DEBUG
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
- // 1 bit is needed to initialize the bit-stream ahead (i.e. if 7
- // bits are in *p and we write 57 bits, then the next write will
- // access a byte that was never initialized).
- uint8_t *p = &array[*pos >> 3];
- uint64_t v = *p;
v |= bits << (*pos & 7);
- BROTLI_UNALIGNED_STORE64(p, v); // Set some bits.
+ BROTLI_UNALIGNED_STORE64(p, v); /* Set some bits. */
*pos += n_bits;
#else
- // implicit & 0xff is assumed for uint8_t arithmetics
+ /* implicit & 0xff is assumed for uint8_t arithmetics */
uint8_t *array_pos = &array[*pos >> 3];
const size_t bits_reserved_in_first_byte = (*pos & 7);
+ size_t bits_left_to_write;
bits <<= bits_reserved_in_first_byte;
- *array_pos++ |= static_cast<uint8_t>(bits);
- for (size_t bits_left_to_write = n_bits + bits_reserved_in_first_byte;
+ *array_pos++ |= (uint8_t)bits;
+ for (bits_left_to_write = n_bits + bits_reserved_in_first_byte;
bits_left_to_write >= 9;
bits_left_to_write -= 8) {
bits >>= 8;
- *array_pos++ = static_cast<uint8_t>(bits);
+ *array_pos++ = (uint8_t)bits;
}
*array_pos = 0;
*pos += n_bits;
#endif
}
-inline void WriteBitsPrepareStorage(size_t pos, uint8_t *array) {
+static BROTLI_INLINE void BrotliWriteBitsPrepareStorage(
+ size_t pos, uint8_t *array) {
#ifdef BIT_WRITER_DEBUG
printf("WriteBitsPrepareStorage %10d\n", pos);
#endif
@@ -79,6 +83,8 @@ inline void WriteBitsPrepareStorage(size_t pos, uint8_t *array) {
array[pos >> 3] = 0;
}
-} // namespace brotli
+#if defined(__cplusplus) || defined(c_plusplus)
+} /* extern "C" */
+#endif
-#endif // BROTLI_ENC_WRITE_BITS_H_
+#endif /* BROTLI_ENC_WRITE_BITS_H_ */
« no previous file with comments | « third_party/brotli/enc/utf8_util.cc ('k') | third_party/brotli/include/brotli/decode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698