mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-41902: Micro optimization for range.index if step is 1 (GH-22479)
This commit is contained in:
		
							parent
							
								
									5f22741340
								
							
						
					
					
						commit
						c0f22fb8b3
					
				
					 2 changed files with 12 additions and 5 deletions
				
			
		|  | @ -582,13 +582,19 @@ range_index(rangeobject *r, PyObject *ob) | |||
|         return NULL; | ||||
| 
 | ||||
|     if (contains) { | ||||
|         PyObject *idx, *tmp = PyNumber_Subtract(ob, r->start); | ||||
|         if (tmp == NULL) | ||||
|         PyObject *idx = PyNumber_Subtract(ob, r->start); | ||||
|         if (idx == NULL) { | ||||
|             return NULL; | ||||
|         } | ||||
| 
 | ||||
|         if (r->step == _PyLong_One) { | ||||
|             return idx; | ||||
|         } | ||||
| 
 | ||||
|         /* idx = (ob - r.start) // r.step */ | ||||
|         idx = PyNumber_FloorDivide(tmp, r->step); | ||||
|         Py_DECREF(tmp); | ||||
|         return idx; | ||||
|         PyObject *sidx = PyNumber_FloorDivide(idx, r->step); | ||||
|         Py_DECREF(idx); | ||||
|         return sidx; | ||||
|     } | ||||
| 
 | ||||
|     /* object is not in the range */ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dong-hee Na
						Dong-hee Na