mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get the new speedup code to compile on windows
This commit is contained in:
parent
3f4bc4764e
commit
2923a20b3c
@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#ifndef uint32_t
|
#ifndef uint32_t
|
||||||
#define unsigned __int32 uint32_t;
|
typedef unsigned __int32 uint32_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef uint8_t
|
#ifndef uint8_t
|
||||||
#define unsigned char uint8_t;
|
typedef unsigned __int8 uint8_t;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -240,7 +240,7 @@ speedup_websocket_mask(PyObject *self, PyObject *args) {
|
|||||||
ans = PyBytes_FromStringAndSize(NULL, PyBytes_GET_SIZE(data));
|
ans = PyBytes_FromStringAndSize(NULL, PyBytes_GET_SIZE(data));
|
||||||
if (ans != NULL) {
|
if (ans != NULL) {
|
||||||
data_buf = PyBytes_AS_STRING(data); mask_buf = PyBytes_AS_STRING(mask); ans_buf = PyBytes_AS_STRING(ans);
|
data_buf = PyBytes_AS_STRING(data); mask_buf = PyBytes_AS_STRING(mask); ans_buf = PyBytes_AS_STRING(ans);
|
||||||
for(i = 0; i < PyBytes_GET_SIZE(ans); i++)
|
for(i = 0; i < (size_t)PyBytes_GET_SIZE(ans); i++)
|
||||||
ans_buf[i] = data_buf[i] ^ mask_buf[(i + offset) & 3];
|
ans_buf[i] = data_buf[i] ^ mask_buf[(i + offset) & 3];
|
||||||
}
|
}
|
||||||
return ans;
|
return ans;
|
||||||
@ -270,7 +270,11 @@ static const uint8_t utf8d[] = {
|
|||||||
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
|
1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
static void __inline
|
||||||
|
#else
|
||||||
static void inline
|
static void inline
|
||||||
|
#endif
|
||||||
utf8_decode_(uint32_t* state, uint32_t* codep, uint8_t byte) {
|
utf8_decode_(uint32_t* state, uint32_t* codep, uint8_t byte) {
|
||||||
/* Comes from http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ */
|
/* Comes from http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ */
|
||||||
uint32_t type = utf8d[byte];
|
uint32_t type = utf8d[byte];
|
||||||
@ -288,13 +292,13 @@ utf8_decode(PyObject *self, PyObject *args) {
|
|||||||
PyObject *data = NULL, *ans = NULL;
|
PyObject *data = NULL, *ans = NULL;
|
||||||
Py_ssize_t i = 0, pos = 0;
|
Py_ssize_t i = 0, pos = 0;
|
||||||
uint32_t *buf = NULL;
|
uint32_t *buf = NULL;
|
||||||
unsigned char *dbuf = NULL;
|
uint8_t *dbuf = NULL;
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "O|II", &data, &state, &codep)) return NULL;
|
if(!PyArg_ParseTuple(args, "O|II", &data, &state, &codep)) return NULL;
|
||||||
|
|
||||||
buf = (uint32_t*)PyMem_Malloc(sizeof(uint32_t) * PyBytes_GET_SIZE(data));
|
buf = (uint32_t*)PyMem_Malloc(sizeof(uint32_t) * PyBytes_GET_SIZE(data));
|
||||||
if (buf == NULL) return PyErr_NoMemory();
|
if (buf == NULL) return PyErr_NoMemory();
|
||||||
dbuf = (unsigned char*)PyBytes_AS_STRING(data);
|
dbuf = (uint8_t*)PyBytes_AS_STRING(data);
|
||||||
|
|
||||||
for (i = 0; i < PyBytes_GET_SIZE(data); i++) {
|
for (i = 0; i < PyBytes_GET_SIZE(data); i++) {
|
||||||
utf8_decode_(&state, &codep, dbuf[i]);
|
utf8_decode_(&state, &codep, dbuf[i]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user