Issue #28126: Replace Py_MEMCPY with memcpy(). Visual Studio can properly optimize memcpy().
This commit is contained in:
parent
a4d9b17b1f
commit
f051e43b22
|
@ -177,26 +177,9 @@ typedef int Py_ssize_clean_t;
|
||||||
#define Py_LOCAL_INLINE(type) static type
|
#define Py_LOCAL_INLINE(type) static type
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
|
/* Py_MEMCPY is kept for backwards compatibility,
|
||||||
* are often very short. While most platforms have highly optimized code for
|
* see https://bugs.python.org/issue28126 */
|
||||||
* large transfers, the setup costs for memcpy are often quite high. MEMCPY
|
|
||||||
* solves this by doing short copies "in line".
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#define Py_MEMCPY(target, source, length) do { \
|
|
||||||
size_t i_, n_ = (length); \
|
|
||||||
char *t_ = (void*) (target); \
|
|
||||||
const char *s_ = (void*) (source); \
|
|
||||||
if (n_ >= 16) \
|
|
||||||
memcpy(t_, s_, n_); \
|
|
||||||
else \
|
|
||||||
for (i_ = 0; i_ < n_; i_++) \
|
|
||||||
t_[i_] = s_[i_]; \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define Py_MEMCPY memcpy
|
#define Py_MEMCPY memcpy
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -449,18 +432,18 @@ extern "C" {
|
||||||
#define HAVE_PY_SET_53BIT_PRECISION 1
|
#define HAVE_PY_SET_53BIT_PRECISION 1
|
||||||
#define _Py_SET_53BIT_PRECISION_HEADER \
|
#define _Py_SET_53BIT_PRECISION_HEADER \
|
||||||
unsigned int old_fpcr, new_fpcr
|
unsigned int old_fpcr, new_fpcr
|
||||||
#define _Py_SET_53BIT_PRECISION_START \
|
#define _Py_SET_53BIT_PRECISION_START \
|
||||||
do { \
|
do { \
|
||||||
__asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
|
__asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
|
||||||
/* Set double precision / round to nearest. */ \
|
/* Set double precision / round to nearest. */ \
|
||||||
new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
|
new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
|
||||||
if (new_fpcr != old_fpcr) \
|
if (new_fpcr != old_fpcr) \
|
||||||
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
|
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define _Py_SET_53BIT_PRECISION_END \
|
#define _Py_SET_53BIT_PRECISION_END \
|
||||||
do { \
|
do { \
|
||||||
if (new_fpcr != old_fpcr) \
|
if (new_fpcr != old_fpcr) \
|
||||||
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
|
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -742,7 +725,7 @@ extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VA_LIST_IS_ARRAY
|
#ifdef VA_LIST_IS_ARRAY
|
||||||
#define Py_VA_COPY(x, y) Py_MEMCPY((x), (y), sizeof(va_list))
|
#define Py_VA_COPY(x, y) memcpy((x), (y), sizeof(va_list))
|
||||||
#else
|
#else
|
||||||
#ifdef __va_copy
|
#ifdef __va_copy
|
||||||
#define Py_VA_COPY __va_copy
|
#define Py_VA_COPY __va_copy
|
||||||
|
|
|
@ -156,7 +156,7 @@ typedef uint8_t Py_UCS1;
|
||||||
Py_UNICODE_ISNUMERIC(ch))
|
Py_UNICODE_ISNUMERIC(ch))
|
||||||
|
|
||||||
#define Py_UNICODE_COPY(target, source, length) \
|
#define Py_UNICODE_COPY(target, source, length) \
|
||||||
Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE))
|
memcpy((target), (source), (length)*sizeof(Py_UNICODE))
|
||||||
|
|
||||||
#define Py_UNICODE_FILL(target, value, length) \
|
#define Py_UNICODE_FILL(target, value, length) \
|
||||||
do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\
|
do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #28126: Replace Py_MEMCPY with memcpy(). Visual Studio can properly
|
||||||
|
optimize memcpy().
|
||||||
|
|
||||||
- Issue #28120: Fix dict.pop() for splitted dictionary when trying to remove a
|
- Issue #28120: Fix dict.pop() for splitted dictionary when trying to remove a
|
||||||
"pending key" (Not yet inserted in split-table). Patch by Xiang Zhang.
|
"pending key" (Not yet inserted in split-table). Patch by Xiang Zhang.
|
||||||
|
|
||||||
|
|
|
@ -836,10 +836,10 @@ array_repeat(arrayobject *a, Py_ssize_t n)
|
||||||
memset(np->ob_item, a->ob_item[0], newbytes);
|
memset(np->ob_item, a->ob_item[0], newbytes);
|
||||||
} else {
|
} else {
|
||||||
Py_ssize_t done = oldbytes;
|
Py_ssize_t done = oldbytes;
|
||||||
Py_MEMCPY(np->ob_item, a->ob_item, oldbytes);
|
memcpy(np->ob_item, a->ob_item, oldbytes);
|
||||||
while (done < newbytes) {
|
while (done < newbytes) {
|
||||||
Py_ssize_t ncopy = (done <= newbytes-done) ? done : newbytes-done;
|
Py_ssize_t ncopy = (done <= newbytes-done) ? done : newbytes-done;
|
||||||
Py_MEMCPY(np->ob_item+done, np->ob_item, ncopy);
|
memcpy(np->ob_item+done, np->ob_item, ncopy);
|
||||||
done += ncopy;
|
done += ncopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,14 +64,14 @@
|
||||||
#define ENTRY_READ_PDATA(TABLE, ENTRY, DATA_SIZE, PDATA) \
|
#define ENTRY_READ_PDATA(TABLE, ENTRY, DATA_SIZE, PDATA) \
|
||||||
do { \
|
do { \
|
||||||
assert((DATA_SIZE) == (TABLE)->data_size); \
|
assert((DATA_SIZE) == (TABLE)->data_size); \
|
||||||
Py_MEMCPY((PDATA), _Py_HASHTABLE_ENTRY_PDATA(TABLE, (ENTRY)), \
|
memcpy((PDATA), _Py_HASHTABLE_ENTRY_PDATA(TABLE, (ENTRY)), \
|
||||||
(DATA_SIZE)); \
|
(DATA_SIZE)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ENTRY_WRITE_PDATA(TABLE, ENTRY, DATA_SIZE, PDATA) \
|
#define ENTRY_WRITE_PDATA(TABLE, ENTRY, DATA_SIZE, PDATA) \
|
||||||
do { \
|
do { \
|
||||||
assert((DATA_SIZE) == (TABLE)->data_size); \
|
assert((DATA_SIZE) == (TABLE)->data_size); \
|
||||||
Py_MEMCPY((void *)_Py_HASHTABLE_ENTRY_PDATA((TABLE), (ENTRY)), \
|
memcpy((void *)_Py_HASHTABLE_ENTRY_PDATA((TABLE), (ENTRY)), \
|
||||||
(PDATA), (DATA_SIZE)); \
|
(PDATA), (DATA_SIZE)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ _Py_hashtable_set(_Py_hashtable_t *ht, size_t key_size, const void *pkey,
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->key_hash = key_hash;
|
entry->key_hash = key_hash;
|
||||||
Py_MEMCPY((void *)_Py_HASHTABLE_ENTRY_PKEY(entry), pkey, ht->key_size);
|
memcpy((void *)_Py_HASHTABLE_ENTRY_PKEY(entry), pkey, ht->key_size);
|
||||||
if (data)
|
if (data)
|
||||||
ENTRY_WRITE_PDATA(ht, entry, data_size, data);
|
ENTRY_WRITE_PDATA(ht, entry, data_size, data);
|
||||||
|
|
||||||
|
|
|
@ -43,26 +43,26 @@ typedef struct {
|
||||||
#define _Py_HASHTABLE_READ_KEY(TABLE, PKEY, DST_KEY) \
|
#define _Py_HASHTABLE_READ_KEY(TABLE, PKEY, DST_KEY) \
|
||||||
do { \
|
do { \
|
||||||
assert(sizeof(DST_KEY) == (TABLE)->key_size); \
|
assert(sizeof(DST_KEY) == (TABLE)->key_size); \
|
||||||
Py_MEMCPY(&(DST_KEY), (PKEY), sizeof(DST_KEY)); \
|
memcpy(&(DST_KEY), (PKEY), sizeof(DST_KEY)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define _Py_HASHTABLE_ENTRY_READ_KEY(TABLE, ENTRY, KEY) \
|
#define _Py_HASHTABLE_ENTRY_READ_KEY(TABLE, ENTRY, KEY) \
|
||||||
do { \
|
do { \
|
||||||
assert(sizeof(KEY) == (TABLE)->key_size); \
|
assert(sizeof(KEY) == (TABLE)->key_size); \
|
||||||
Py_MEMCPY(&(KEY), _Py_HASHTABLE_ENTRY_PKEY(ENTRY), sizeof(KEY)); \
|
memcpy(&(KEY), _Py_HASHTABLE_ENTRY_PKEY(ENTRY), sizeof(KEY)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define _Py_HASHTABLE_ENTRY_READ_DATA(TABLE, ENTRY, DATA) \
|
#define _Py_HASHTABLE_ENTRY_READ_DATA(TABLE, ENTRY, DATA) \
|
||||||
do { \
|
do { \
|
||||||
assert(sizeof(DATA) == (TABLE)->data_size); \
|
assert(sizeof(DATA) == (TABLE)->data_size); \
|
||||||
Py_MEMCPY(&(DATA), _Py_HASHTABLE_ENTRY_PDATA(TABLE, (ENTRY)), \
|
memcpy(&(DATA), _Py_HASHTABLE_ENTRY_PDATA(TABLE, (ENTRY)), \
|
||||||
sizeof(DATA)); \
|
sizeof(DATA)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define _Py_HASHTABLE_ENTRY_WRITE_DATA(TABLE, ENTRY, DATA) \
|
#define _Py_HASHTABLE_ENTRY_WRITE_DATA(TABLE, ENTRY, DATA) \
|
||||||
do { \
|
do { \
|
||||||
assert(sizeof(DATA) == (TABLE)->data_size); \
|
assert(sizeof(DATA) == (TABLE)->data_size); \
|
||||||
Py_MEMCPY((void *)_Py_HASHTABLE_ENTRY_PDATA((TABLE), (ENTRY)), \
|
memcpy((void *)_Py_HASHTABLE_ENTRY_PDATA((TABLE), (ENTRY)), \
|
||||||
&(DATA), sizeof(DATA)); \
|
&(DATA), sizeof(DATA)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -721,9 +721,9 @@ save_unconsumed_input(compobject *self, Py_buffer *data, int err)
|
||||||
new_data = PyBytes_FromStringAndSize(NULL, new_size);
|
new_data = PyBytes_FromStringAndSize(NULL, new_size);
|
||||||
if (new_data == NULL)
|
if (new_data == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
Py_MEMCPY(PyBytes_AS_STRING(new_data),
|
memcpy(PyBytes_AS_STRING(new_data),
|
||||||
PyBytes_AS_STRING(self->unused_data), old_size);
|
PyBytes_AS_STRING(self->unused_data), old_size);
|
||||||
Py_MEMCPY(PyBytes_AS_STRING(new_data) + old_size,
|
memcpy(PyBytes_AS_STRING(new_data) + old_size,
|
||||||
self->zst.next_in, left_size);
|
self->zst.next_in, left_size);
|
||||||
Py_SETREF(self->unused_data, new_data);
|
Py_SETREF(self->unused_data, new_data);
|
||||||
self->zst.avail_in = 0;
|
self->zst.avail_in = 0;
|
||||||
|
|
|
@ -2353,7 +2353,7 @@ _PyObject_Call_Prepend(PyObject *func,
|
||||||
|
|
||||||
/* use borrowed references */
|
/* use borrowed references */
|
||||||
stack[0] = obj;
|
stack[0] = obj;
|
||||||
Py_MEMCPY(&stack[1],
|
memcpy(&stack[1],
|
||||||
&PyTuple_GET_ITEM(args, 0),
|
&PyTuple_GET_ITEM(args, 0),
|
||||||
argcount * sizeof(PyObject *));
|
argcount * sizeof(PyObject *));
|
||||||
|
|
||||||
|
@ -2428,7 +2428,7 @@ _PyStack_UnpackDict(PyObject **args, Py_ssize_t nargs, PyObject *kwargs,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy position arguments (borrowed references) */
|
/* Copy position arguments (borrowed references) */
|
||||||
Py_MEMCPY(stack, args, nargs * sizeof(stack[0]));
|
memcpy(stack, args, nargs * sizeof(stack[0]));
|
||||||
|
|
||||||
kwstack = stack + nargs;
|
kwstack = stack + nargs;
|
||||||
pos = i = 0;
|
pos = i = 0;
|
||||||
|
|
|
@ -120,7 +120,7 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return (PyObject *) op;
|
return (PyObject *) op;
|
||||||
|
|
||||||
Py_MEMCPY(op->ob_sval, str, size);
|
memcpy(op->ob_sval, str, size);
|
||||||
/* share short strings */
|
/* share short strings */
|
||||||
if (size == 1) {
|
if (size == 1) {
|
||||||
characters[*str & UCHAR_MAX] = op;
|
characters[*str & UCHAR_MAX] = op;
|
||||||
|
@ -163,7 +163,7 @@ PyBytes_FromString(const char *str)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
(void)PyObject_INIT_VAR(op, &PyBytes_Type, size);
|
(void)PyObject_INIT_VAR(op, &PyBytes_Type, size);
|
||||||
op->ob_shash = -1;
|
op->ob_shash = -1;
|
||||||
Py_MEMCPY(op->ob_sval, str, size+1);
|
memcpy(op->ob_sval, str, size+1);
|
||||||
/* share short strings */
|
/* share short strings */
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
nullstring = op;
|
nullstring = op;
|
||||||
|
@ -437,7 +437,7 @@ formatfloat(PyObject *v, int flags, int prec, int type,
|
||||||
str = _PyBytesWriter_Prepare(writer, str, len);
|
str = _PyBytesWriter_Prepare(writer, str, len);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_MEMCPY(str, p, len);
|
memcpy(str, p, len);
|
||||||
PyMem_Free(p);
|
PyMem_Free(p);
|
||||||
str += len;
|
str += len;
|
||||||
return str;
|
return str;
|
||||||
|
@ -626,7 +626,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
||||||
len = format_len - (fmt - format);
|
len = format_len - (fmt - format);
|
||||||
assert(len != 0);
|
assert(len != 0);
|
||||||
|
|
||||||
Py_MEMCPY(res, fmt, len);
|
memcpy(res, fmt, len);
|
||||||
res += len;
|
res += len;
|
||||||
fmt += len;
|
fmt += len;
|
||||||
fmtcnt -= (len - 1);
|
fmtcnt -= (len - 1);
|
||||||
|
@ -1009,7 +1009,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy bytes */
|
/* Copy bytes */
|
||||||
Py_MEMCPY(res, pbuf, len);
|
memcpy(res, pbuf, len);
|
||||||
res += len;
|
res += len;
|
||||||
|
|
||||||
/* Pad right with the fill character if needed */
|
/* Pad right with the fill character if needed */
|
||||||
|
@ -1473,12 +1473,12 @@ bytes_repeat(PyBytesObject *a, Py_ssize_t n)
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
if (i < size) {
|
if (i < size) {
|
||||||
Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
|
memcpy(op->ob_sval, a->ob_sval, Py_SIZE(a));
|
||||||
i = Py_SIZE(a);
|
i = Py_SIZE(a);
|
||||||
}
|
}
|
||||||
while (i < size) {
|
while (i < size) {
|
||||||
j = (i <= size-i) ? i : size-i;
|
j = (i <= size-i) ? i : size-i;
|
||||||
Py_MEMCPY(op->ob_sval+i, op->ob_sval, j);
|
memcpy(op->ob_sval+i, op->ob_sval, j);
|
||||||
i += j;
|
i += j;
|
||||||
}
|
}
|
||||||
return (PyObject *) op;
|
return (PyObject *) op;
|
||||||
|
@ -2765,7 +2765,7 @@ bytes_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
n = PyBytes_GET_SIZE(tmp);
|
n = PyBytes_GET_SIZE(tmp);
|
||||||
pnew = type->tp_alloc(type, n);
|
pnew = type->tp_alloc(type, n);
|
||||||
if (pnew != NULL) {
|
if (pnew != NULL) {
|
||||||
Py_MEMCPY(PyBytes_AS_STRING(pnew),
|
memcpy(PyBytes_AS_STRING(pnew),
|
||||||
PyBytes_AS_STRING(tmp), n+1);
|
PyBytes_AS_STRING(tmp), n+1);
|
||||||
((PyBytesObject *)pnew)->ob_shash =
|
((PyBytesObject *)pnew)->ob_shash =
|
||||||
((PyBytesObject *)tmp)->ob_shash;
|
((PyBytesObject *)tmp)->ob_shash;
|
||||||
|
@ -3237,7 +3237,7 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size)
|
||||||
dest = PyByteArray_AS_STRING(writer->buffer);
|
dest = PyByteArray_AS_STRING(writer->buffer);
|
||||||
else
|
else
|
||||||
dest = PyBytes_AS_STRING(writer->buffer);
|
dest = PyBytes_AS_STRING(writer->buffer);
|
||||||
Py_MEMCPY(dest,
|
memcpy(dest,
|
||||||
writer->small_buffer,
|
writer->small_buffer,
|
||||||
pos);
|
pos);
|
||||||
}
|
}
|
||||||
|
@ -3372,7 +3372,7 @@ _PyBytesWriter_WriteBytes(_PyBytesWriter *writer, void *ptr,
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Py_MEMCPY(str, bytes, size);
|
memcpy(str, bytes, size);
|
||||||
str += size;
|
str += size;
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
|
|
@ -107,7 +107,7 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||||
for (i = 0; i < nbufs; i++) {
|
for (i = 0; i < nbufs; i++) {
|
||||||
Py_ssize_t n = buffers[i].len;
|
Py_ssize_t n = buffers[i].len;
|
||||||
char *q = buffers[i].buf;
|
char *q = buffers[i].buf;
|
||||||
Py_MEMCPY(p, q, n);
|
memcpy(p, q, n);
|
||||||
p += n;
|
p += n;
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -116,12 +116,12 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
|
||||||
Py_ssize_t n;
|
Py_ssize_t n;
|
||||||
char *q;
|
char *q;
|
||||||
if (i) {
|
if (i) {
|
||||||
Py_MEMCPY(p, sepstr, seplen);
|
memcpy(p, sepstr, seplen);
|
||||||
p += seplen;
|
p += seplen;
|
||||||
}
|
}
|
||||||
n = buffers[i].len;
|
n = buffers[i].len;
|
||||||
q = buffers[i].buf;
|
q = buffers[i].buf;
|
||||||
Py_MEMCPY(p, q, n);
|
memcpy(p, q, n);
|
||||||
p += n;
|
p += n;
|
||||||
}
|
}
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
@ -108,7 +108,7 @@ pad(PyObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
|
||||||
if (u) {
|
if (u) {
|
||||||
if (left)
|
if (left)
|
||||||
memset(STRINGLIB_STR(u), fill, left);
|
memset(STRINGLIB_STR(u), fill, left);
|
||||||
Py_MEMCPY(STRINGLIB_STR(u) + left,
|
memcpy(STRINGLIB_STR(u) + left,
|
||||||
STRINGLIB_STR(self),
|
STRINGLIB_STR(self),
|
||||||
STRINGLIB_LEN(self));
|
STRINGLIB_LEN(self));
|
||||||
if (right)
|
if (right)
|
||||||
|
@ -275,13 +275,13 @@ stringlib_replace_interleave(PyObject *self,
|
||||||
|
|
||||||
if (to_len > 1) {
|
if (to_len > 1) {
|
||||||
/* Lay the first one down (guaranteed this will occur) */
|
/* Lay the first one down (guaranteed this will occur) */
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
memcpy(result_s, to_s, to_len);
|
||||||
result_s += to_len;
|
result_s += to_len;
|
||||||
count -= 1;
|
count -= 1;
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
*result_s++ = *self_s++;
|
*result_s++ = *self_s++;
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
memcpy(result_s, to_s, to_len);
|
||||||
result_s += to_len;
|
result_s += to_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ stringlib_replace_interleave(PyObject *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the rest of the original string */
|
/* Copy the rest of the original string */
|
||||||
Py_MEMCPY(result_s, self_s, self_len - i);
|
memcpy(result_s, self_s, self_len - i);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -337,11 +337,11 @@ stringlib_replace_delete_single_character(PyObject *self,
|
||||||
next = findchar(start, end - start, from_c);
|
next = findchar(start, end - start, from_c);
|
||||||
if (next == NULL)
|
if (next == NULL)
|
||||||
break;
|
break;
|
||||||
Py_MEMCPY(result_s, start, next - start);
|
memcpy(result_s, start, next - start);
|
||||||
result_s += (next - start);
|
result_s += (next - start);
|
||||||
start = next + 1;
|
start = next + 1;
|
||||||
}
|
}
|
||||||
Py_MEMCPY(result_s, start, end - start);
|
memcpy(result_s, start, end - start);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -390,12 +390,12 @@ stringlib_replace_delete_substring(PyObject *self,
|
||||||
break;
|
break;
|
||||||
next = start + offset;
|
next = start + offset;
|
||||||
|
|
||||||
Py_MEMCPY(result_s, start, next - start);
|
memcpy(result_s, start, next - start);
|
||||||
|
|
||||||
result_s += (next - start);
|
result_s += (next - start);
|
||||||
start = next + from_len;
|
start = next + from_len;
|
||||||
}
|
}
|
||||||
Py_MEMCPY(result_s, start, end - start);
|
memcpy(result_s, start, end - start);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ stringlib_replace_single_character_in_place(PyObject *self,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result_s = STRINGLIB_STR(result);
|
result_s = STRINGLIB_STR(result);
|
||||||
Py_MEMCPY(result_s, self_s, self_len);
|
memcpy(result_s, self_s, self_len);
|
||||||
|
|
||||||
/* change everything in-place, starting with this one */
|
/* change everything in-place, starting with this one */
|
||||||
start = result_s + (next - self_s);
|
start = result_s + (next - self_s);
|
||||||
|
@ -477,11 +477,11 @@ stringlib_replace_substring_in_place(PyObject *self,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result_s = STRINGLIB_STR(result);
|
result_s = STRINGLIB_STR(result);
|
||||||
Py_MEMCPY(result_s, self_s, self_len);
|
memcpy(result_s, self_s, self_len);
|
||||||
|
|
||||||
/* change everything in-place, starting with this one */
|
/* change everything in-place, starting with this one */
|
||||||
start = result_s + offset;
|
start = result_s + offset;
|
||||||
Py_MEMCPY(start, to_s, from_len);
|
memcpy(start, to_s, from_len);
|
||||||
start += from_len;
|
start += from_len;
|
||||||
end = result_s + self_len;
|
end = result_s + self_len;
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ stringlib_replace_substring_in_place(PyObject *self,
|
||||||
0);
|
0);
|
||||||
if (offset == -1)
|
if (offset == -1)
|
||||||
break;
|
break;
|
||||||
Py_MEMCPY(start + offset, to_s, from_len);
|
memcpy(start + offset, to_s, from_len);
|
||||||
start += offset + from_len;
|
start += offset + from_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,20 +544,20 @@ stringlib_replace_single_character(PyObject *self,
|
||||||
|
|
||||||
if (next == start) {
|
if (next == start) {
|
||||||
/* replace with the 'to' */
|
/* replace with the 'to' */
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
memcpy(result_s, to_s, to_len);
|
||||||
result_s += to_len;
|
result_s += to_len;
|
||||||
start += 1;
|
start += 1;
|
||||||
} else {
|
} else {
|
||||||
/* copy the unchanged old then the 'to' */
|
/* copy the unchanged old then the 'to' */
|
||||||
Py_MEMCPY(result_s, start, next - start);
|
memcpy(result_s, start, next - start);
|
||||||
result_s += (next - start);
|
result_s += (next - start);
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
memcpy(result_s, to_s, to_len);
|
||||||
result_s += to_len;
|
result_s += to_len;
|
||||||
start = next + 1;
|
start = next + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Copy the remainder of the remaining bytes */
|
/* Copy the remainder of the remaining bytes */
|
||||||
Py_MEMCPY(result_s, start, end - start);
|
memcpy(result_s, start, end - start);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -613,20 +613,20 @@ stringlib_replace_substring(PyObject *self,
|
||||||
next = start + offset;
|
next = start + offset;
|
||||||
if (next == start) {
|
if (next == start) {
|
||||||
/* replace with the 'to' */
|
/* replace with the 'to' */
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
memcpy(result_s, to_s, to_len);
|
||||||
result_s += to_len;
|
result_s += to_len;
|
||||||
start += from_len;
|
start += from_len;
|
||||||
} else {
|
} else {
|
||||||
/* copy the unchanged old then the 'to' */
|
/* copy the unchanged old then the 'to' */
|
||||||
Py_MEMCPY(result_s, start, next - start);
|
memcpy(result_s, start, next - start);
|
||||||
result_s += (next - start);
|
result_s += (next - start);
|
||||||
Py_MEMCPY(result_s, to_s, to_len);
|
memcpy(result_s, to_s, to_len);
|
||||||
result_s += to_len;
|
result_s += to_len;
|
||||||
start = next + from_len;
|
start = next + from_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Copy the remainder of the remaining bytes */
|
/* Copy the remainder of the remaining bytes */
|
||||||
Py_MEMCPY(result_s, start, end - start);
|
memcpy(result_s, start, end - start);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1048,7 +1048,7 @@ resize_copy(PyObject *unicode, Py_ssize_t length)
|
||||||
return NULL;
|
return NULL;
|
||||||
copy_length = _PyUnicode_WSTR_LENGTH(unicode);
|
copy_length = _PyUnicode_WSTR_LENGTH(unicode);
|
||||||
copy_length = Py_MIN(copy_length, length);
|
copy_length = Py_MIN(copy_length, length);
|
||||||
Py_MEMCPY(_PyUnicode_WSTR(w), _PyUnicode_WSTR(unicode),
|
memcpy(_PyUnicode_WSTR(w), _PyUnicode_WSTR(unicode),
|
||||||
copy_length * sizeof(wchar_t));
|
copy_length * sizeof(wchar_t));
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -1435,7 +1435,7 @@ _copy_characters(PyObject *to, Py_ssize_t to_start,
|
||||||
if (max_char >= 128)
|
if (max_char >= 128)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Py_MEMCPY((char*)to_data + to_kind * to_start,
|
memcpy((char*)to_data + to_kind * to_start,
|
||||||
(char*)from_data + from_kind * from_start,
|
(char*)from_data + from_kind * from_start,
|
||||||
to_kind * how_many);
|
to_kind * how_many);
|
||||||
}
|
}
|
||||||
|
@ -2024,7 +2024,7 @@ PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
|
||||||
break;
|
break;
|
||||||
case PyUnicode_2BYTE_KIND:
|
case PyUnicode_2BYTE_KIND:
|
||||||
#if Py_UNICODE_SIZE == 2
|
#if Py_UNICODE_SIZE == 2
|
||||||
Py_MEMCPY(PyUnicode_2BYTE_DATA(unicode), u, size * 2);
|
memcpy(PyUnicode_2BYTE_DATA(unicode), u, size * 2);
|
||||||
#else
|
#else
|
||||||
_PyUnicode_CONVERT_BYTES(Py_UNICODE, Py_UCS2,
|
_PyUnicode_CONVERT_BYTES(Py_UNICODE, Py_UCS2,
|
||||||
u, u + size, PyUnicode_2BYTE_DATA(unicode));
|
u, u + size, PyUnicode_2BYTE_DATA(unicode));
|
||||||
|
@ -2037,7 +2037,7 @@ PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
|
||||||
unicode_convert_wchar_to_ucs4(u, u + size, unicode);
|
unicode_convert_wchar_to_ucs4(u, u + size, unicode);
|
||||||
#else
|
#else
|
||||||
assert(num_surrogates == 0);
|
assert(num_surrogates == 0);
|
||||||
Py_MEMCPY(PyUnicode_4BYTE_DATA(unicode), u, size * 4);
|
memcpy(PyUnicode_4BYTE_DATA(unicode), u, size * 4);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -2348,7 +2348,7 @@ _PyUnicode_Copy(PyObject *unicode)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(PyUnicode_KIND(copy) == PyUnicode_KIND(unicode));
|
assert(PyUnicode_KIND(copy) == PyUnicode_KIND(unicode));
|
||||||
|
|
||||||
Py_MEMCPY(PyUnicode_DATA(copy), PyUnicode_DATA(unicode),
|
memcpy(PyUnicode_DATA(copy), PyUnicode_DATA(unicode),
|
||||||
length * PyUnicode_KIND(unicode));
|
length * PyUnicode_KIND(unicode));
|
||||||
assert(_PyUnicode_CheckConsistency(copy, 1));
|
assert(_PyUnicode_CheckConsistency(copy, 1));
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -2454,7 +2454,7 @@ as_ucs4(PyObject *string, Py_UCS4 *target, Py_ssize_t targetsize,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(kind == PyUnicode_4BYTE_KIND);
|
assert(kind == PyUnicode_4BYTE_KIND);
|
||||||
Py_MEMCPY(target, data, len * sizeof(Py_UCS4));
|
memcpy(target, data, len * sizeof(Py_UCS4));
|
||||||
}
|
}
|
||||||
if (copy_null)
|
if (copy_null)
|
||||||
target[len] = 0;
|
target[len] = 0;
|
||||||
|
@ -2963,7 +2963,7 @@ unicode_aswidechar(PyObject *unicode,
|
||||||
size = res + 1;
|
size = res + 1;
|
||||||
else
|
else
|
||||||
res = size;
|
res = size;
|
||||||
Py_MEMCPY(w, wstr, size * sizeof(wchar_t));
|
memcpy(w, wstr, size * sizeof(wchar_t));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -3986,7 +3986,7 @@ PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *psize)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
_PyUnicode_UTF8_LENGTH(unicode) = PyBytes_GET_SIZE(bytes);
|
_PyUnicode_UTF8_LENGTH(unicode) = PyBytes_GET_SIZE(bytes);
|
||||||
Py_MEMCPY(_PyUnicode_UTF8(unicode),
|
memcpy(_PyUnicode_UTF8(unicode),
|
||||||
PyBytes_AS_STRING(bytes),
|
PyBytes_AS_STRING(bytes),
|
||||||
_PyUnicode_UTF8_LENGTH(unicode) + 1);
|
_PyUnicode_UTF8_LENGTH(unicode) + 1);
|
||||||
Py_DECREF(bytes);
|
Py_DECREF(bytes);
|
||||||
|
@ -5473,7 +5473,7 @@ _PyUnicode_EncodeUTF32(PyObject *str,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyBytes_Check(rep)) {
|
if (PyBytes_Check(rep)) {
|
||||||
Py_MEMCPY(out, PyBytes_AS_STRING(rep), repsize);
|
memcpy(out, PyBytes_AS_STRING(rep), repsize);
|
||||||
out += moreunits;
|
out += moreunits;
|
||||||
} else /* rep is unicode */ {
|
} else /* rep is unicode */ {
|
||||||
assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND);
|
assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND);
|
||||||
|
@ -5825,7 +5825,7 @@ _PyUnicode_EncodeUTF16(PyObject *str,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyBytes_Check(rep)) {
|
if (PyBytes_Check(rep)) {
|
||||||
Py_MEMCPY(out, PyBytes_AS_STRING(rep), repsize);
|
memcpy(out, PyBytes_AS_STRING(rep), repsize);
|
||||||
out += moreunits;
|
out += moreunits;
|
||||||
} else /* rep is unicode */ {
|
} else /* rep is unicode */ {
|
||||||
assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND);
|
assert(PyUnicode_KIND(rep) == PyUnicode_1BYTE_KIND);
|
||||||
|
@ -10012,7 +10012,7 @@ _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen)
|
||||||
|
|
||||||
/* Copy item, and maybe the separator. */
|
/* Copy item, and maybe the separator. */
|
||||||
if (i && seplen != 0) {
|
if (i && seplen != 0) {
|
||||||
Py_MEMCPY(res_data,
|
memcpy(res_data,
|
||||||
sep_data,
|
sep_data,
|
||||||
kind * seplen);
|
kind * seplen);
|
||||||
res_data += kind * seplen;
|
res_data += kind * seplen;
|
||||||
|
@ -10020,7 +10020,7 @@ _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen)
|
||||||
|
|
||||||
itemlen = PyUnicode_GET_LENGTH(item);
|
itemlen = PyUnicode_GET_LENGTH(item);
|
||||||
if (itemlen != 0) {
|
if (itemlen != 0) {
|
||||||
Py_MEMCPY(res_data,
|
memcpy(res_data,
|
||||||
PyUnicode_DATA(item),
|
PyUnicode_DATA(item),
|
||||||
kind * itemlen);
|
kind * itemlen);
|
||||||
res_data += kind * itemlen;
|
res_data += kind * itemlen;
|
||||||
|
@ -12396,11 +12396,11 @@ unicode_repeat(PyObject *str, Py_ssize_t len)
|
||||||
Py_ssize_t done = PyUnicode_GET_LENGTH(str);
|
Py_ssize_t done = PyUnicode_GET_LENGTH(str);
|
||||||
const Py_ssize_t char_size = PyUnicode_KIND(str);
|
const Py_ssize_t char_size = PyUnicode_KIND(str);
|
||||||
char *to = (char *) PyUnicode_DATA(u);
|
char *to = (char *) PyUnicode_DATA(u);
|
||||||
Py_MEMCPY(to, PyUnicode_DATA(str),
|
memcpy(to, PyUnicode_DATA(str),
|
||||||
PyUnicode_GET_LENGTH(str) * char_size);
|
PyUnicode_GET_LENGTH(str) * char_size);
|
||||||
while (done < nchars) {
|
while (done < nchars) {
|
||||||
n = (done <= nchars-done) ? done : nchars-done;
|
n = (done <= nchars-done) ? done : nchars-done;
|
||||||
Py_MEMCPY(to + (done * char_size), to, n * char_size);
|
memcpy(to + (done * char_size), to, n * char_size);
|
||||||
done += n;
|
done += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13531,7 +13531,7 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer,
|
||||||
const Py_UCS1 *str = (const Py_UCS1 *)ascii;
|
const Py_UCS1 *str = (const Py_UCS1 *)ascii;
|
||||||
Py_UCS1 *data = writer->data;
|
Py_UCS1 *data = writer->data;
|
||||||
|
|
||||||
Py_MEMCPY(data + writer->pos, str, len);
|
memcpy(data + writer->pos, str, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PyUnicode_2BYTE_KIND:
|
case PyUnicode_2BYTE_KIND:
|
||||||
|
@ -14928,7 +14928,7 @@ unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
_PyUnicode_WSTR(self) = (wchar_t *)data;
|
_PyUnicode_WSTR(self) = (wchar_t *)data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_MEMCPY(data, PyUnicode_DATA(unicode),
|
memcpy(data, PyUnicode_DATA(unicode),
|
||||||
kind * (length + 1));
|
kind * (length + 1));
|
||||||
assert(_PyUnicode_CheckConsistency(self, 1));
|
assert(_PyUnicode_CheckConsistency(self, 1));
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
|
|
|
@ -130,7 +130,7 @@ w_string(const char *s, Py_ssize_t n, WFILE *p)
|
||||||
m = p->end - p->ptr;
|
m = p->end - p->ptr;
|
||||||
if (p->fp != NULL) {
|
if (p->fp != NULL) {
|
||||||
if (n <= m) {
|
if (n <= m) {
|
||||||
Py_MEMCPY(p->ptr, s, n);
|
memcpy(p->ptr, s, n);
|
||||||
p->ptr += n;
|
p->ptr += n;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -140,7 +140,7 @@ w_string(const char *s, Py_ssize_t n, WFILE *p)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (n <= m || w_reserve(p, n - m)) {
|
if (n <= m || w_reserve(p, n - m)) {
|
||||||
Py_MEMCPY(p->ptr, s, n);
|
memcpy(p->ptr, s, n);
|
||||||
p->ptr += n;
|
p->ptr += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,7 +396,7 @@ siphash24(const void *src, Py_ssize_t src_sz) {
|
||||||
case 7: pt[6] = m[6];
|
case 7: pt[6] = m[6];
|
||||||
case 6: pt[5] = m[5];
|
case 6: pt[5] = m[5];
|
||||||
case 5: pt[4] = m[4];
|
case 5: pt[4] = m[4];
|
||||||
case 4: Py_MEMCPY(pt, m, sizeof(uint32_t)); break;
|
case 4: memcpy(pt, m, sizeof(uint32_t)); break;
|
||||||
case 3: pt[2] = m[2];
|
case 3: pt[2] = m[2];
|
||||||
case 2: pt[1] = m[1];
|
case 2: pt[1] = m[1];
|
||||||
case 1: pt[0] = m[0];
|
case 1: pt[0] = m[0];
|
||||||
|
|
Loading…
Reference in New Issue