Mercurial > public > mercurial-scm > hg
comparison contrib/python-zstandard/zstd/common/bitstream.h @ 40121:73fef626dae3
zstandard: vendor python-zstandard 0.10.1
This was just released.
The upstream source distribution from PyPI was extracted. Unwanted
files were removed.
The clang-format ignore list was updated to reflect the new source
of files.
setup.py was updated to pass a new argument to python-zstandard's
function for returning an Extension instance. Upstream had to change
to use relative paths because Python 3.7's packaging doesn't
seem to like absolute paths when defining sources, includes, etc.
The default relative path calculation is relative to setup_zstd.py
which is different from the directory of Mercurial's setup.py.
The project contains a vendored copy of zstandard 1.3.6. The old
version was 1.3.4.
The API should be backwards compatible and nothing in core should
need adjusted. However, there is a new "chunker" API that we
may find useful in places where we want to emit compressed chunks
of a fixed size.
There are a pair of bug fixes in 0.10.0 with regards to
compressobj() and decompressobj() when block flushing is used. I
actually found these bugs when introducing these APIs in Mercurial!
But existing Mercurial code is not affected because we don't
perform block flushing.
# no-check-commit because 3rd party code has different style guidelines
Differential Revision: https://phab.mercurial-scm.org/D4911
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 08 Oct 2018 16:27:40 -0700 |
parents | b1fb341d8a61 |
children | 675775c33ab6 |
comparison
equal
deleted
inserted
replaced
40120:89742f1fa6cb | 40121:73fef626dae3 |
---|---|
1 /* ****************************************************************** | 1 /* ****************************************************************** |
2 bitstream | 2 bitstream |
3 Part of FSE library | 3 Part of FSE library |
4 header file (to include) | 4 Copyright (C) 2013-present, Yann Collet. |
5 Copyright (C) 2013-2017, Yann Collet. | |
6 | 5 |
7 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) | 6 BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) |
8 | 7 |
9 Redistribution and use in source and binary forms, with or without | 8 Redistribution and use in source and binary forms, with or without |
10 modification, are permitted provided that the following conditions are | 9 modification, are permitted provided that the following conditions are |
47 | 46 |
48 /*-**************************************** | 47 /*-**************************************** |
49 * Dependencies | 48 * Dependencies |
50 ******************************************/ | 49 ******************************************/ |
51 #include "mem.h" /* unaligned access routines */ | 50 #include "mem.h" /* unaligned access routines */ |
51 #include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */ | |
52 #include "error_private.h" /* error codes and messages */ | 52 #include "error_private.h" /* error codes and messages */ |
53 | |
54 | |
55 /*-************************************* | |
56 * Debug | |
57 ***************************************/ | |
58 #if defined(BIT_DEBUG) && (BIT_DEBUG>=1) | |
59 # include <assert.h> | |
60 #else | |
61 # ifndef assert | |
62 # define assert(condition) ((void)0) | |
63 # endif | |
64 #endif | |
65 | 53 |
66 | 54 |
67 /*========================================= | 55 /*========================================= |
68 * Target specific | 56 * Target specific |
69 =========================================*/ | 57 =========================================*/ |
81 ********************************************/ | 69 ********************************************/ |
82 /* bitStream can mix input from multiple sources. | 70 /* bitStream can mix input from multiple sources. |
83 * A critical property of these streams is that they encode and decode in **reverse** direction. | 71 * A critical property of these streams is that they encode and decode in **reverse** direction. |
84 * So the first bit sequence you add will be the last to be read, like a LIFO stack. | 72 * So the first bit sequence you add will be the last to be read, like a LIFO stack. |
85 */ | 73 */ |
86 typedef struct | 74 typedef struct { |
87 { | |
88 size_t bitContainer; | 75 size_t bitContainer; |
89 unsigned bitPos; | 76 unsigned bitPos; |
90 char* startPtr; | 77 char* startPtr; |
91 char* ptr; | 78 char* ptr; |
92 char* endPtr; | 79 char* endPtr; |
116 | 103 |
117 | 104 |
118 /*-******************************************** | 105 /*-******************************************** |
119 * bitStream decoding API (read backward) | 106 * bitStream decoding API (read backward) |
120 **********************************************/ | 107 **********************************************/ |
121 typedef struct | 108 typedef struct { |
122 { | |
123 size_t bitContainer; | 109 size_t bitContainer; |
124 unsigned bitsConsumed; | 110 unsigned bitsConsumed; |
125 const char* ptr; | 111 const char* ptr; |
126 const char* start; | 112 const char* start; |
127 const char* limitPtr; | 113 const char* limitPtr; |
234 bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos; | 220 bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos; |
235 bitC->bitPos += nbBits; | 221 bitC->bitPos += nbBits; |
236 } | 222 } |
237 | 223 |
238 /*! BIT_addBitsFast() : | 224 /*! BIT_addBitsFast() : |
239 * works only if `value` is _clean_, meaning all high bits above nbBits are 0 */ | 225 * works only if `value` is _clean_, |
226 * meaning all high bits above nbBits are 0 */ | |
240 MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, | 227 MEM_STATIC void BIT_addBitsFast(BIT_CStream_t* bitC, |
241 size_t value, unsigned nbBits) | 228 size_t value, unsigned nbBits) |
242 { | 229 { |
243 assert((value>>nbBits) == 0); | 230 assert((value>>nbBits) == 0); |
244 assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); | 231 assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8); |