diff options
| author | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-28 12:06:46 +0000 |
|---|---|---|
| committer | Fredrik Lundh <fredrik@pythonware.com> | 2006-05-28 12:06:46 +0000 |
| commit | ce20ee34ef5ff250d67103d31aad9956a9c64c67 (patch) | |
| tree | c53e749ede1d5e42451785749de82a230109ff13 /Include/pyport.h | |
| parent | 6a5c67a8f02e6ca6e22541ce4b6b96136c0a53a7 (diff) | |
| download | cpython-ce20ee34ef5ff250d67103d31aad9956a9c64c67.tar.gz | |
needforspeed: added Py_MEMCPY macro (currently tuned for Visual C only),
and use it for string copy operations. this gives a 20% speedup on some
string benchmarks.
Diffstat (limited to 'Include/pyport.h')
| -rw-r--r-- | Include/pyport.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Include/pyport.h b/Include/pyport.h index 74ce993497..47b9f70628 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -174,6 +174,27 @@ typedef Py_intptr_t Py_ssize_t; #define Py_LOCAL_INLINE(type) static type #endif +/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks + * are often very short. While most platforms have highly optimized code for + * 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 +#endif + #include <stdlib.h> #include <math.h> /* Moved here from the math section, before extern "C" */ |
