mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	needforspeed: speed up unicode repeat, unicode string copy
This commit is contained in:
		
							parent
							
								
									d82c3105cc
								
							
						
					
					
						commit
						f1d60a5384
					
				
					 2 changed files with 14 additions and 8 deletions
				
			
		| 
						 | 
					@ -352,12 +352,15 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
 | 
				
			||||||
        Py_UNICODE_ISDIGIT(ch) || \
 | 
					        Py_UNICODE_ISDIGIT(ch) || \
 | 
				
			||||||
        Py_UNICODE_ISNUMERIC(ch))
 | 
					        Py_UNICODE_ISNUMERIC(ch))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define Py_UNICODE_COPY(target, source, length)\
 | 
					#define Py_UNICODE_COPY(target, source, length) do\
 | 
				
			||||||
    (memcpy((target), (source), (length)*sizeof(Py_UNICODE)))
 | 
					    {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\
 | 
					#define Py_UNICODE_FILL(target, value, length) do\
 | 
				
			||||||
    {int i; for (i = 0; i < (length); i++) (target)[i] = (value);}\
 | 
					    {int i; Py_UNICODE *t = (target); Py_UNICODE v = (value);\
 | 
				
			||||||
    while (0)
 | 
					        for (i = 0; i < (length); i++) t[i] = v;\
 | 
				
			||||||
 | 
					    } while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define Py_UNICODE_MATCH(string, offset, substring)\
 | 
					#define Py_UNICODE_MATCH(string, offset, substring)\
 | 
				
			||||||
    ((*((string)->str + (offset)) == *((substring)->str)) &&\
 | 
					    ((*((string)->str + (offset)) == *((substring)->str)) &&\
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5898,6 +5898,9 @@ unicode_repeat(PyUnicodeObject *str, Py_ssize_t len)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p = u->str;
 | 
					    p = u->str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (str->length == 1 && len > 0) {
 | 
				
			||||||
 | 
					        Py_UNICODE_FILL(p, str->str[0], len);
 | 
				
			||||||
 | 
					    } else
 | 
				
			||||||
        while (len-- > 0) {
 | 
					        while (len-- > 0) {
 | 
				
			||||||
            Py_UNICODE_COPY(p, str->str, str->length);
 | 
					            Py_UNICODE_COPY(p, str->str, str->length);
 | 
				
			||||||
            p += str->length;
 | 
					            p += str->length;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue