[Python-checkins] r46076 - in python/trunk: Include/unicodeobject.h Objects/unicodeobject.c

M.-A. Lemburg mal at egenix.com
Mon May 22 18:46:50 CEST 2006


fredrik.lundh wrote:
> Author: fredrik.lundh
> Date: Mon May 22 18:29:30 2006
> New Revision: 46076
> 
> Modified:
>    python/trunk/Include/unicodeobject.h
>    python/trunk/Objects/unicodeobject.c
> Log:
> needforspeed: speed up unicode repeat, unicode string copy
> 
> 
> 
> Modified: python/trunk/Include/unicodeobject.h
> ==============================================================================
> --- python/trunk/Include/unicodeobject.h	(original)
> +++ python/trunk/Include/unicodeobject.h	Mon May 22 18:29:30 2006
> @@ -352,12 +352,15 @@
>          Py_UNICODE_ISDIGIT(ch) || \
>          Py_UNICODE_ISNUMERIC(ch))
>  
> -#define Py_UNICODE_COPY(target, source, length)\
> -    (memcpy((target), (source), (length)*sizeof(Py_UNICODE)))
> +#define Py_UNICODE_COPY(target, source, length) do\
> +    {int i; Py_UNICODE *t = (target); const Py_UNICODE *s = (source);\
> +        for (i = 0; i < (length); i++) t[i] = s[i];\
> +    } while (0)

Hi Fredrik,

why is the for()-loop faster than the memcpy and if so, on which
platforms ?

>  #define Py_UNICODE_FILL(target, value, length) do\
> -    {int i; for (i = 0; i < (length); i++) (target)[i] = (value);}\
> -    while (0)
> +    {int i; Py_UNICODE *t = (target); Py_UNICODE v = (value);\
> +        for (i = 0; i < (length); i++) t[i] = v;\
> +    } while (0)

Dito here: why not use memset() ?!

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 22 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the Python-checkins mailing list