[Python-checkins] r46076 - in python/trunk: Include/unicodeobject.h Objects/unicodeobject.c
fredrik.lundh
python-checkins at python.org
Mon May 22 18:29:45 CEST 2006
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)
#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)
#define Py_UNICODE_MATCH(string, offset, substring)\
((*((string)->str + (offset)) == *((substring)->str)) &&\
Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c (original)
+++ python/trunk/Objects/unicodeobject.c Mon May 22 18:29:30 2006
@@ -5898,10 +5898,13 @@
p = u->str;
- while (len-- > 0) {
- Py_UNICODE_COPY(p, str->str, str->length);
- p += str->length;
- }
+ if (str->length == 1 && len > 0) {
+ Py_UNICODE_FILL(p, str->str[0], len);
+ } else
+ while (len-- > 0) {
+ Py_UNICODE_COPY(p, str->str, str->length);
+ p += str->length;
+ }
return (PyObject*) u;
}
More information about the Python-checkins
mailing list