mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Small code improvements for readability, code size, and/or speed.
BINARY_SUBSCR:
    * invert test for normal case fall through
    * eliminate err handling code by jumping to slow_case
LOAD_LOCALS:
    * invert test for normal case fall through
    * continue instead of break for the non-error case
STORE_NAME and DELETE_NAME:
    * invert test for normal case fall through
LOAD_NAME:
    * continue instead of break for the non-error case
DELETE_FAST:
    * invert test for normal case fall through
LOAD_DEREF:
    * invert test for normal case fall through
    * continue instead of break for the non-error case
			
			
This commit is contained in:
		
							parent
							
								
									22ab06e4de
								
							
						
					
					
						commit
						467a698bd2
					
				
					 1 changed files with 55 additions and 59 deletions
				
			
		
							
								
								
									
										114
									
								
								Python/ceval.c
									
										
									
									
									
								
							
							
						
						
									
										114
									
								
								Python/ceval.c
									
										
									
									
									
								
							|  | @ -1155,18 +1155,15 @@ eval_frame(PyFrameObject *f) | ||||||
| 				long i = PyInt_AsLong(w); | 				long i = PyInt_AsLong(w); | ||||||
| 				if (i < 0) | 				if (i < 0) | ||||||
| 					i += PyList_GET_SIZE(v); | 					i += PyList_GET_SIZE(v); | ||||||
| 				if (i < 0 || | 				if (i >= 0 && i < PyList_GET_SIZE(v)) { | ||||||
| 				    i >= PyList_GET_SIZE(v)) { |  | ||||||
| 					PyErr_SetString(PyExc_IndexError, |  | ||||||
| 						"list index out of range"); |  | ||||||
| 					x = NULL; |  | ||||||
| 				} |  | ||||||
| 				else { |  | ||||||
| 					x = PyList_GET_ITEM(v, i); | 					x = PyList_GET_ITEM(v, i); | ||||||
| 					Py_INCREF(x); | 					Py_INCREF(x); | ||||||
| 				} | 				} | ||||||
|  | 				else | ||||||
|  | 					goto slow_get; | ||||||
| 			} | 			} | ||||||
| 			else | 			else | ||||||
|  | 			  slow_get: | ||||||
| 				x = PyObject_GetItem(v, w); | 				x = PyObject_GetItem(v, w); | ||||||
| 			Py_DECREF(v); | 			Py_DECREF(v); | ||||||
| 			Py_DECREF(w); | 			Py_DECREF(w); | ||||||
|  | @ -1608,13 +1605,12 @@ eval_frame(PyFrameObject *f) | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
| 		case LOAD_LOCALS: | 		case LOAD_LOCALS: | ||||||
| 			if ((x = f->f_locals) == NULL) { | 			if ((x = f->f_locals) != NULL) { | ||||||
| 				PyErr_SetString(PyExc_SystemError, | 				Py_INCREF(x); | ||||||
| 						"no locals"); | 				PUSH(x); | ||||||
| 				break; | 				continue; | ||||||
| 			} | 			} | ||||||
| 			Py_INCREF(x); | 			PyErr_SetString(PyExc_SystemError, "no locals"); | ||||||
| 			PUSH(x); |  | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
| 		case RETURN_VALUE: | 		case RETURN_VALUE: | ||||||
|  | @ -1687,27 +1683,27 @@ eval_frame(PyFrameObject *f) | ||||||
| 		case STORE_NAME: | 		case STORE_NAME: | ||||||
| 			w = GETITEM(names, oparg); | 			w = GETITEM(names, oparg); | ||||||
| 			v = POP(); | 			v = POP(); | ||||||
| 			if ((x = f->f_locals) == NULL) { | 			if ((x = f->f_locals) != NULL) { | ||||||
| 				PyErr_Format(PyExc_SystemError, | 				err = PyDict_SetItem(x, w, v); | ||||||
| 					     "no locals found when storing %s", | 				Py_DECREF(v); | ||||||
| 					     PyObject_REPR(w)); |  | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 			err = PyDict_SetItem(x, w, v); | 			PyErr_Format(PyExc_SystemError, | ||||||
| 			Py_DECREF(v); | 				     "no locals found when storing %s", | ||||||
|  | 				     PyObject_REPR(w)); | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
| 		case DELETE_NAME: | 		case DELETE_NAME: | ||||||
| 			w = GETITEM(names, oparg); | 			w = GETITEM(names, oparg); | ||||||
| 			if ((x = f->f_locals) == NULL) { | 			if ((x = f->f_locals) != NULL) { | ||||||
| 				PyErr_Format(PyExc_SystemError, | 				if ((err = PyDict_DelItem(x, w)) != 0) | ||||||
| 					     "no locals when deleting %s", | 					format_exc_check_arg(PyExc_NameError, | ||||||
| 					     PyObject_REPR(w)); | 								NAME_ERROR_MSG ,w); | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 			if ((err = PyDict_DelItem(x, w)) != 0) | 			PyErr_Format(PyExc_SystemError, | ||||||
| 				format_exc_check_arg(PyExc_NameError, | 				     "no locals when deleting %s", | ||||||
| 							NAME_ERROR_MSG ,w); | 				     PyObject_REPR(w)); | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
| 		PREDICTED_WITH_ARG(UNPACK_SEQUENCE); | 		PREDICTED_WITH_ARG(UNPACK_SEQUENCE); | ||||||
|  | @ -1794,7 +1790,7 @@ eval_frame(PyFrameObject *f) | ||||||
| 			} | 			} | ||||||
| 			Py_INCREF(x); | 			Py_INCREF(x); | ||||||
| 			PUSH(x); | 			PUSH(x); | ||||||
| 			break; | 			continue; | ||||||
| 
 | 
 | ||||||
| 		case LOAD_GLOBAL: | 		case LOAD_GLOBAL: | ||||||
| 			w = GETITEM(names, oparg); | 			w = GETITEM(names, oparg); | ||||||
|  | @ -1840,16 +1836,16 @@ eval_frame(PyFrameObject *f) | ||||||
| 
 | 
 | ||||||
| 		case DELETE_FAST: | 		case DELETE_FAST: | ||||||
| 			x = GETLOCAL(oparg); | 			x = GETLOCAL(oparg); | ||||||
| 			if (x == NULL) { | 			if (x != NULL) { | ||||||
| 				format_exc_check_arg( | 				SETLOCAL(oparg, NULL); | ||||||
| 					PyExc_UnboundLocalError, | 				continue; | ||||||
| 					UNBOUNDLOCAL_ERROR_MSG, |  | ||||||
| 					PyTuple_GetItem(co->co_varnames, oparg) |  | ||||||
| 					); |  | ||||||
| 				break; |  | ||||||
| 			} | 			} | ||||||
| 			SETLOCAL(oparg, NULL); | 			format_exc_check_arg( | ||||||
| 			continue; | 				PyExc_UnboundLocalError, | ||||||
|  | 				UNBOUNDLOCAL_ERROR_MSG, | ||||||
|  | 				PyTuple_GetItem(co->co_varnames, oparg) | ||||||
|  | 				); | ||||||
|  | 			break; | ||||||
| 
 | 
 | ||||||
| 		case LOAD_CLOSURE: | 		case LOAD_CLOSURE: | ||||||
| 			x = freevars[oparg]; | 			x = freevars[oparg]; | ||||||
|  | @ -1860,30 +1856,30 @@ eval_frame(PyFrameObject *f) | ||||||
| 		case LOAD_DEREF: | 		case LOAD_DEREF: | ||||||
| 			x = freevars[oparg]; | 			x = freevars[oparg]; | ||||||
| 			w = PyCell_Get(x); | 			w = PyCell_Get(x); | ||||||
| 			if (w == NULL) { | 			if (w != NULL) { | ||||||
| 				err = -1; | 				PUSH(w); | ||||||
| 				/* Don't stomp existing exception */ | 				continue; | ||||||
| 				if (PyErr_Occurred()) | 			} | ||||||
| 					break; | 			err = -1; | ||||||
| 				if (oparg < f->f_ncells) { | 			/* Don't stomp existing exception */ | ||||||
| 					v = PyTuple_GetItem(co->co_cellvars, | 			if (PyErr_Occurred()) | ||||||
| 							       oparg); | 				break; | ||||||
| 				       format_exc_check_arg( | 			if (oparg < f->f_ncells) { | ||||||
| 					       PyExc_UnboundLocalError, | 				v = PyTuple_GetItem(co->co_cellvars, | ||||||
| 					       UNBOUNDLOCAL_ERROR_MSG, | 						       oparg); | ||||||
| 					       v); | 			       format_exc_check_arg( | ||||||
| 				} else { | 				       PyExc_UnboundLocalError, | ||||||
| 				       v = PyTuple_GetItem( | 				       UNBOUNDLOCAL_ERROR_MSG, | ||||||
| 						      co->co_freevars, | 				       v); | ||||||
| 						      oparg - f->f_ncells); | 			} else { | ||||||
| 				       format_exc_check_arg( | 			       v = PyTuple_GetItem( | ||||||
| 					       PyExc_NameError, | 					      co->co_freevars, | ||||||
| 					       UNBOUNDFREE_ERROR_MSG, | 					      oparg - f->f_ncells); | ||||||
| 					       v); | 			       format_exc_check_arg( | ||||||
| 				} | 				       PyExc_NameError, | ||||||
| 				break; | 				       UNBOUNDFREE_ERROR_MSG, | ||||||
|  | 				       v); | ||||||
| 			} | 			} | ||||||
| 			PUSH(w); |  | ||||||
| 			break; | 			break; | ||||||
| 
 | 
 | ||||||
| 		case STORE_DEREF: | 		case STORE_DEREF: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger