Mercurial > public > mercurial-scm > hg
comparison contrib/python-zstandard/c-ext/compressionparams.c @ 31796:e0dc40530c5a
zstd: vendor python-zstandard 0.8.0
Commit 81e1f5bbf1fc54808649562d3ed829730765c540 from
https://github.com/indygreg/python-zstandard is imported without
modifications (other than removing unwanted files).
Updates relevant to Mercurial include:
* Support for multi-threaded compression (we can use this for
bundle and wire protocol compression).
* APIs for batch compression and decompression operations using
multiple threads and optimal memory allocation mechanism. (Can
be useful for revlog perf improvements.)
* A ``BufferWithSegments`` type that models a single memory buffer
containing N discrete items of known lengths. This type can be
used for very efficient 0-copy data operations.
# no-check-commit
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 01 Apr 2017 15:24:03 -0700 |
parents | c32454d69b85 |
children | b1fb341d8a61 |
comparison
equal
deleted
inserted
replaced
31795:2b130e26c3a4 | 31796:e0dc40530c5a |
---|---|
65 unsigned hashLog; | 65 unsigned hashLog; |
66 unsigned searchLog; | 66 unsigned searchLog; |
67 unsigned searchLength; | 67 unsigned searchLength; |
68 unsigned targetLength; | 68 unsigned targetLength; |
69 unsigned strategy; | 69 unsigned strategy; |
70 ZSTD_compressionParameters params; | |
71 size_t zresult; | |
70 | 72 |
71 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "IIIIIII:CompressionParameters", | 73 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "IIIIIII:CompressionParameters", |
72 kwlist, &windowLog, &chainLog, &hashLog, &searchLog, &searchLength, | 74 kwlist, &windowLog, &chainLog, &hashLog, &searchLog, &searchLength, |
73 &targetLength, &strategy)) { | 75 &targetLength, &strategy)) { |
74 return -1; | 76 return -1; |
115 self->searchLog = searchLog; | 117 self->searchLog = searchLog; |
116 self->searchLength = searchLength; | 118 self->searchLength = searchLength; |
117 self->targetLength = targetLength; | 119 self->targetLength = targetLength; |
118 self->strategy = strategy; | 120 self->strategy = strategy; |
119 | 121 |
122 ztopy_compression_parameters(self, ¶ms); | |
123 zresult = ZSTD_checkCParams(params); | |
124 | |
125 if (ZSTD_isError(zresult)) { | |
126 PyErr_Format(PyExc_ValueError, "invalid compression parameters: %s", | |
127 ZSTD_getErrorName(zresult)); | |
128 return -1; | |
129 } | |
130 | |
120 return 0; | 131 return 0; |
132 } | |
133 | |
134 PyDoc_STRVAR(CompressionParameters_estimated_compression_context_size__doc__, | |
135 "Estimate the size in bytes of a compression context for compression parameters\n" | |
136 ); | |
137 | |
138 PyObject* CompressionParameters_estimated_compression_context_size(CompressionParametersObject* self) { | |
139 ZSTD_compressionParameters params; | |
140 | |
141 ztopy_compression_parameters(self, ¶ms); | |
142 | |
143 return PyLong_FromSize_t(ZSTD_estimateCCtxSize(params)); | |
121 } | 144 } |
122 | 145 |
123 PyObject* estimate_compression_context_size(PyObject* self, PyObject* args) { | 146 PyObject* estimate_compression_context_size(PyObject* self, PyObject* args) { |
124 CompressionParametersObject* params; | 147 CompressionParametersObject* params; |
125 ZSTD_compressionParameters zparams; | 148 ZSTD_compressionParameters zparams; |
139 "CompressionParameters: low-level control over zstd compression"); | 162 "CompressionParameters: low-level control over zstd compression"); |
140 | 163 |
141 static void CompressionParameters_dealloc(PyObject* self) { | 164 static void CompressionParameters_dealloc(PyObject* self) { |
142 PyObject_Del(self); | 165 PyObject_Del(self); |
143 } | 166 } |
167 | |
168 static PyMethodDef CompressionParameters_methods[] = { | |
169 { | |
170 "estimated_compression_context_size", | |
171 (PyCFunction)CompressionParameters_estimated_compression_context_size, | |
172 METH_NOARGS, | |
173 CompressionParameters_estimated_compression_context_size__doc__ | |
174 }, | |
175 { NULL, NULL } | |
176 }; | |
144 | 177 |
145 static PyMemberDef CompressionParameters_members[] = { | 178 static PyMemberDef CompressionParameters_members[] = { |
146 { "window_log", T_UINT, | 179 { "window_log", T_UINT, |
147 offsetof(CompressionParametersObject, windowLog), READONLY, | 180 offsetof(CompressionParametersObject, windowLog), READONLY, |
148 "window log" }, | 181 "window log" }, |
193 0, /* tp_clear */ | 226 0, /* tp_clear */ |
194 0, /* tp_richcompare */ | 227 0, /* tp_richcompare */ |
195 0, /* tp_weaklistoffset */ | 228 0, /* tp_weaklistoffset */ |
196 0, /* tp_iter */ | 229 0, /* tp_iter */ |
197 0, /* tp_iternext */ | 230 0, /* tp_iternext */ |
198 0, /* tp_methods */ | 231 CompressionParameters_methods, /* tp_methods */ |
199 CompressionParameters_members, /* tp_members */ | 232 CompressionParameters_members, /* tp_members */ |
200 0, /* tp_getset */ | 233 0, /* tp_getset */ |
201 0, /* tp_base */ | 234 0, /* tp_base */ |
202 0, /* tp_dict */ | 235 0, /* tp_dict */ |
203 0, /* tp_descr_get */ | 236 0, /* tp_descr_get */ |
212 Py_TYPE(&CompressionParametersType) = &PyType_Type; | 245 Py_TYPE(&CompressionParametersType) = &PyType_Type; |
213 if (PyType_Ready(&CompressionParametersType) < 0) { | 246 if (PyType_Ready(&CompressionParametersType) < 0) { |
214 return; | 247 return; |
215 } | 248 } |
216 | 249 |
217 Py_IncRef((PyObject*)&CompressionParametersType); | 250 Py_INCREF(&CompressionParametersType); |
218 PyModule_AddObject(mod, "CompressionParameters", | 251 PyModule_AddObject(mod, "CompressionParameters", |
219 (PyObject*)&CompressionParametersType); | 252 (PyObject*)&CompressionParametersType); |
220 } | 253 } |