[Python-checkins] python/dist/src/Python ceval.c,2.379,2.380

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Mon Mar 8 18:25:32 EST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19051

Modified Files:
	ceval.c 
Log Message:
Refactor and optimize code for UNPACK_SEQUENCE.

* Defer error handling for wrong number of arguments to the
  unpack_iterable() function.  Cuts the code size almost in half.

* Replace function calls to PyList_Size() and PyTuple_Size() with
  their smaller and faster macro counterparts.

* Move the constant structure references outside of the inner loops.



Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.379
retrieving revision 2.380
diff -C2 -d -r2.379 -r2.380
*** ceval.c	7 Mar 2004 07:31:05 -0000	2.379
--- ceval.c	8 Mar 2004 23:25:30 -0000	2.380
***************
*** 1722,1754 ****
  		case UNPACK_SEQUENCE:
  			v = POP();
! 			if (PyTuple_CheckExact(v)) {
! 				if (PyTuple_Size(v) != oparg) {
! 					PyErr_SetString(PyExc_ValueError,
! 						 "unpack tuple of wrong size");
! 					why = WHY_EXCEPTION;
! 				}
! 				else {
! 					for (; --oparg >= 0; ) {
! 						w = PyTuple_GET_ITEM(v, oparg);
! 						Py_INCREF(w);
! 						PUSH(w);
! 					}
! 				}
! 			}
! 			else if (PyList_CheckExact(v)) {
! 				if (PyList_Size(v) != oparg) {
! 					PyErr_SetString(PyExc_ValueError,
! 						  "unpack list of wrong size");
! 					why = WHY_EXCEPTION;
  				}
! 				else {
! 					for (; --oparg >= 0; ) {
! 						w = PyList_GET_ITEM(v, oparg);
! 						Py_INCREF(w);
! 						PUSH(w);
! 					}
  				}
! 			}
! 			else if (unpack_iterable(v, oparg,
  						 stack_pointer + oparg))
  				stack_pointer += oparg;
--- 1722,1740 ----
  		case UNPACK_SEQUENCE:
  			v = POP();
! 			if (PyTuple_CheckExact(v) && PyTuple_GET_SIZE(v) == oparg) {
! 				PyObject **items = ((PyTupleObject *)v)->ob_item;
! 				while (oparg--) {
! 					w = items[oparg];
! 					Py_INCREF(w);
! 					PUSH(w);
  				}
! 			} else if (PyList_CheckExact(v) && PyList_GET_SIZE(v) == oparg) {
! 				PyObject **items = ((PyListObject *)v)->ob_item;
! 				while (oparg--) {
! 					w = items[oparg];
! 					Py_INCREF(w);
! 					PUSH(w);
  				}
! 			} else if (unpack_iterable(v, oparg,
  						 stack_pointer + oparg))
  				stack_pointer += oparg;




More information about the Python-checkins mailing list