mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as is done for simple slices, in the tuple, string and unicode case. - Specialcase step-1 extended slices to optimize the common case for all involved types. - For lists, allow extended slice assignment of differing lengths as long as the step is 1. (Previously, 'l[:2:1] = []' failed even though 'l[:2] = []' and 'l[:2:None] = []' do not.) - Implement extended slicing for buffer, array, structseq, mmap and UserString.UserString. - Implement slice-object support (but not non-step-1 slice assignment) for UserString.MutableString. - Add tests for all new functionality.
This commit is contained in:
		
							parent
							
								
									0f4a14b56f
								
							
						
					
					
						commit
						3ccec68a05
					
				
					 16 changed files with 730 additions and 120 deletions
				
			
		|  | @ -7385,6 +7385,12 @@ unicode_subscript(PyUnicodeObject* self, PyObject* item) | |||
| 
 | ||||
|         if (slicelength <= 0) { | ||||
|             return PyUnicode_FromUnicode(NULL, 0); | ||||
|         } else if (start == 0 && step == 1 && slicelength == self->length && | ||||
|                    PyUnicode_CheckExact(self)) { | ||||
|             Py_INCREF(self); | ||||
|             return (PyObject *)self; | ||||
|         } else if (step == 1) { | ||||
|             return PyUnicode_FromUnicode(self->str + start, slicelength); | ||||
|         } else { | ||||
|             source_buf = PyUnicode_AS_UNICODE((PyObject*)self); | ||||
|             result_buf = (Py_UNICODE *)PyMem_MALLOC(slicelength* | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thomas Wouters
						Thomas Wouters