[Python-checkins] python/dist/src/Python compile.c,2.319,2.320

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Aug 18 07:22:09 CEST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22306
Modified Files:
	compile.c 
Log Message:
Move the bytecode optimizer upstream so that its results are saved in pyc
files and not re-optimized upon import. Saves a bit of startup time while
still remaining decoupled from the rest of the compiler.
As a side benefit, handcoded bytecode is not run through the optimizer
when new code objects are created. Hopefully, a handcoder has already
created exactly what they want to have run.
(Idea suggested by Armin Rigo and Michael Hudson. Initially avoided 
 because of worries about compiler coupling; however, only the nexus
 point needed to be moved so there won't be a conflict when the AST
 branch is loaded.)
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.319
retrieving revision 2.320
diff -C2 -d -r2.319 -r2.320
*** compile.c	17 Aug 2004 17:29:15 -0000	2.319
--- compile.c	18 Aug 2004 05:22:06 -0000	2.320
***************
*** 626,630 ****
 		co->co_stacksize = stacksize;
 		co->co_flags = flags;
! 		co->co_code = optimize_code(code, consts, names);
 		Py_INCREF(consts);
 		co->co_consts = consts;
--- 626,631 ----
 		co->co_stacksize = stacksize;
 		co->co_flags = flags;
! 		Py_INCREF(code);
! 		co->co_code = code;
 		Py_INCREF(consts);
 		co->co_consts = consts;
***************
*** 4792,4796 ****
 	if (sc.c_errors == 0) {
 		PyObject *consts, *names, *varnames, *filename, *name,
! 			*freevars, *cellvars;
 		consts = PyList_AsTuple(sc.c_consts);
 		names = PyList_AsTuple(sc.c_names);
--- 4793,4797 ----
 	if (sc.c_errors == 0) {
 		PyObject *consts, *names, *varnames, *filename, *name,
! 			*freevars, *cellvars, *code;
 		consts = PyList_AsTuple(sc.c_consts);
 		names = PyList_AsTuple(sc.c_names);
***************
*** 4801,4804 ****
--- 4802,4806 ----
 		filename = PyString_InternFromString(sc.c_filename);
 		name = PyString_InternFromString(sc.c_name);
+ 		code = optimize_code(sc.c_code, consts, names);
 		if (!PyErr_Occurred())
 			co = PyCode_New(sc.c_argcount,
***************
*** 4806,4810 ****
 					sc.c_maxstacklevel,
 					sc.c_flags,
! 					sc.c_code,
 					consts,
 					names,
--- 4808,4812 ----
 					sc.c_maxstacklevel,
 					sc.c_flags,
! 					code,
 					consts,
 					names,
***************
*** 4823,4826 ****
--- 4825,4829 ----
 		Py_XDECREF(filename);
 		Py_XDECREF(name);
+ 		Py_XDECREF(code);
 	}
 	else if (!PyErr_Occurred()) {


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /