Mercurial > public > mercurial-scm > hg
comparison contrib/python-zstandard/c-ext/compressionparams.c @ 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 |
---|---|
37 TRY_SET_PARAMETER(params, ZSTD_p_checksumFlag, obj->checksumFlag); | 37 TRY_SET_PARAMETER(params, ZSTD_p_checksumFlag, obj->checksumFlag); |
38 TRY_SET_PARAMETER(params, ZSTD_p_dictIDFlag, obj->dictIDFlag); | 38 TRY_SET_PARAMETER(params, ZSTD_p_dictIDFlag, obj->dictIDFlag); |
39 TRY_SET_PARAMETER(params, ZSTD_p_nbWorkers, obj->threads); | 39 TRY_SET_PARAMETER(params, ZSTD_p_nbWorkers, obj->threads); |
40 TRY_SET_PARAMETER(params, ZSTD_p_jobSize, obj->jobSize); | 40 TRY_SET_PARAMETER(params, ZSTD_p_jobSize, obj->jobSize); |
41 TRY_SET_PARAMETER(params, ZSTD_p_overlapSizeLog, obj->overlapSizeLog); | 41 TRY_SET_PARAMETER(params, ZSTD_p_overlapSizeLog, obj->overlapSizeLog); |
42 TRY_SET_PARAMETER(params, ZSTD_p_compressLiterals, obj->compressLiterals); | |
43 TRY_SET_PARAMETER(params, ZSTD_p_forceMaxWindow, obj->forceMaxWindow); | 42 TRY_SET_PARAMETER(params, ZSTD_p_forceMaxWindow, obj->forceMaxWindow); |
44 TRY_SET_PARAMETER(params, ZSTD_p_enableLongDistanceMatching, obj->enableLongDistanceMatching); | 43 TRY_SET_PARAMETER(params, ZSTD_p_enableLongDistanceMatching, obj->enableLongDistanceMatching); |
45 TRY_SET_PARAMETER(params, ZSTD_p_ldmHashLog, obj->ldmHashLog); | 44 TRY_SET_PARAMETER(params, ZSTD_p_ldmHashLog, obj->ldmHashLog); |
46 TRY_SET_PARAMETER(params, ZSTD_p_ldmMinMatch, obj->ldmMinMatch); | 45 TRY_SET_PARAMETER(params, ZSTD_p_ldmMinMatch, obj->ldmMinMatch); |
47 TRY_SET_PARAMETER(params, ZSTD_p_ldmBucketSizeLog, obj->ldmBucketSizeLog); | 46 TRY_SET_PARAMETER(params, ZSTD_p_ldmBucketSizeLog, obj->ldmBucketSizeLog); |
86 "ldm_hash_log", | 85 "ldm_hash_log", |
87 "ldm_min_match", | 86 "ldm_min_match", |
88 "ldm_bucket_size_log", | 87 "ldm_bucket_size_log", |
89 "ldm_hash_every_log", | 88 "ldm_hash_every_log", |
90 "threads", | 89 "threads", |
91 "compress_literals", | |
92 NULL | 90 NULL |
93 }; | 91 }; |
94 | 92 |
95 unsigned format = 0; | 93 unsigned format = 0; |
96 int compressionLevel = 0; | 94 int compressionLevel = 0; |
112 unsigned ldmMinMatch = 0; | 110 unsigned ldmMinMatch = 0; |
113 unsigned ldmBucketSizeLog = 0; | 111 unsigned ldmBucketSizeLog = 0; |
114 unsigned ldmHashEveryLog = 0; | 112 unsigned ldmHashEveryLog = 0; |
115 int threads = 0; | 113 int threads = 0; |
116 | 114 |
117 /* Setting value 0 has the effect of disabling. So we use -1 as a default | |
118 * to detect whether to set. Then we automatically derive the expected value | |
119 * based on the level, just like zstandard does itself. */ | |
120 int compressLiterals = -1; | |
121 | |
122 if (!PyArg_ParseTupleAndKeywords(args, kwargs, | 115 if (!PyArg_ParseTupleAndKeywords(args, kwargs, |
123 "|IiIIIIIIIIIIIIIIIIIIii:CompressionParameters", | 116 "|IiIIIIIIIIIIIIIIIIIIi:CompressionParameters", |
124 kwlist, &format, &compressionLevel, &windowLog, &hashLog, &chainLog, | 117 kwlist, &format, &compressionLevel, &windowLog, &hashLog, &chainLog, |
125 &searchLog, &minMatch, &targetLength, &compressionStrategy, | 118 &searchLog, &minMatch, &targetLength, &compressionStrategy, |
126 &contentSizeFlag, &checksumFlag, &dictIDFlag, &jobSize, &overlapSizeLog, | 119 &contentSizeFlag, &checksumFlag, &dictIDFlag, &jobSize, &overlapSizeLog, |
127 &forceMaxWindow, &enableLDM, &ldmHashLog, &ldmMinMatch, &ldmBucketSizeLog, | 120 &forceMaxWindow, &enableLDM, &ldmHashLog, &ldmMinMatch, &ldmBucketSizeLog, |
128 &ldmHashEveryLog, &threads, &compressLiterals)) { | 121 &ldmHashEveryLog, &threads)) { |
129 return -1; | 122 return -1; |
130 } | 123 } |
131 | 124 |
132 if (threads < 0) { | 125 if (threads < 0) { |
133 threads = cpu_count(); | 126 threads = cpu_count(); |
134 } | |
135 | |
136 if (compressLiterals < 0) { | |
137 compressLiterals = compressionLevel >= 0; | |
138 } | 127 } |
139 | 128 |
140 self->format = format; | 129 self->format = format; |
141 self->compressionLevel = compressionLevel; | 130 self->compressionLevel = compressionLevel; |
142 self->windowLog = windowLog; | 131 self->windowLog = windowLog; |
150 self->checksumFlag = checksumFlag; | 139 self->checksumFlag = checksumFlag; |
151 self->dictIDFlag = dictIDFlag; | 140 self->dictIDFlag = dictIDFlag; |
152 self->threads = threads; | 141 self->threads = threads; |
153 self->jobSize = jobSize; | 142 self->jobSize = jobSize; |
154 self->overlapSizeLog = overlapSizeLog; | 143 self->overlapSizeLog = overlapSizeLog; |
155 self->compressLiterals = compressLiterals; | |
156 self->forceMaxWindow = forceMaxWindow; | 144 self->forceMaxWindow = forceMaxWindow; |
157 self->enableLongDistanceMatching = enableLDM; | 145 self->enableLongDistanceMatching = enableLDM; |
158 self->ldmHashLog = ldmHashLog; | 146 self->ldmHashLog = ldmHashLog; |
159 self->ldmMinMatch = ldmMinMatch; | 147 self->ldmMinMatch = ldmMinMatch; |
160 self->ldmBucketSizeLog = ldmBucketSizeLog; | 148 self->ldmBucketSizeLog = ldmBucketSizeLog; |
294 val = PyLong_FromUnsignedLong(params.strategy); | 282 val = PyLong_FromUnsignedLong(params.strategy); |
295 if (!val) { | 283 if (!val) { |
296 goto cleanup; | 284 goto cleanup; |
297 } | 285 } |
298 PyDict_SetItemString(kwargs, "compression_strategy", val); | 286 PyDict_SetItemString(kwargs, "compression_strategy", val); |
299 Py_DECREF(val); | |
300 } | |
301 | |
302 val = PyDict_GetItemString(kwargs, "compress_literals"); | |
303 if (!val) { | |
304 val = PyLong_FromLong(level >= 0 ? 1 : 0); | |
305 if (!val) { | |
306 goto cleanup; | |
307 } | |
308 PyDict_SetItemString(kwargs, "compress_literals", val); | |
309 Py_DECREF(val); | 287 Py_DECREF(val); |
310 } | 288 } |
311 | 289 |
312 result = PyObject_New(ZstdCompressionParametersObject, &ZstdCompressionParametersType); | 290 result = PyObject_New(ZstdCompressionParametersObject, &ZstdCompressionParametersType); |
313 if (!result) { | 291 if (!result) { |
418 offsetof(ZstdCompressionParametersObject, jobSize), READONLY, | 396 offsetof(ZstdCompressionParametersObject, jobSize), READONLY, |
419 "size of compression job when using multiple threads" }, | 397 "size of compression job when using multiple threads" }, |
420 { "overlap_size_log", T_UINT, | 398 { "overlap_size_log", T_UINT, |
421 offsetof(ZstdCompressionParametersObject, overlapSizeLog), READONLY, | 399 offsetof(ZstdCompressionParametersObject, overlapSizeLog), READONLY, |
422 "Size of previous input reloaded at the beginning of each job" }, | 400 "Size of previous input reloaded at the beginning of each job" }, |
423 { "compress_literals", T_UINT, | |
424 offsetof(ZstdCompressionParametersObject, compressLiterals), READONLY, | |
425 "whether Huffman compression of literals is in use" }, | |
426 { "force_max_window", T_UINT, | 401 { "force_max_window", T_UINT, |
427 offsetof(ZstdCompressionParametersObject, forceMaxWindow), READONLY, | 402 offsetof(ZstdCompressionParametersObject, forceMaxWindow), READONLY, |
428 "force back references to remain smaller than window size" }, | 403 "force back references to remain smaller than window size" }, |
429 { "enable_ldm", T_UINT, | 404 { "enable_ldm", T_UINT, |
430 offsetof(ZstdCompressionParametersObject, enableLongDistanceMatching), READONLY, | 405 offsetof(ZstdCompressionParametersObject, enableLongDistanceMatching), READONLY, |