mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Improve the reverse list iterator to free memory as soon as the iterator
is exhausted.
This commit is contained in:
		
							parent
							
								
									e21f606657
								
							
						
					
					
						commit
						001f228f36
					
				
					 1 changed files with 4 additions and 1 deletions
				
			
		| 
						 | 
					@ -2771,7 +2771,7 @@ PyTypeObject PyListIter_Type = {
 | 
				
			||||||
typedef struct {
 | 
					typedef struct {
 | 
				
			||||||
	PyObject_HEAD
 | 
						PyObject_HEAD
 | 
				
			||||||
	long it_index;
 | 
						long it_index;
 | 
				
			||||||
	PyListObject *it_seq;
 | 
						PyListObject *it_seq; /* Set to NULL when iterator is exhausted */
 | 
				
			||||||
} listreviterobject;
 | 
					} listreviterobject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PyTypeObject PyListRevIter_Type;
 | 
					PyTypeObject PyListRevIter_Type;
 | 
				
			||||||
| 
						 | 
					@ -2819,6 +2819,9 @@ listreviter_next(listreviterobject *it)
 | 
				
			||||||
		item = PyList_GET_ITEM(it->it_seq, it->it_index);
 | 
							item = PyList_GET_ITEM(it->it_seq, it->it_index);
 | 
				
			||||||
		it->it_index--;
 | 
							it->it_index--;
 | 
				
			||||||
		Py_INCREF(item);
 | 
							Py_INCREF(item);
 | 
				
			||||||
 | 
						} else if (it->it_seq != NULL) {
 | 
				
			||||||
 | 
							Py_DECREF(it->it_seq);
 | 
				
			||||||
 | 
							it->it_seq = NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return item;
 | 
						return item;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue