[Python-checkins] python/dist/src/Parser tokenizer.c,2.64,2.65

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Fri, 16 Aug 2002 10:01:12 -0700


Update of /cvsroot/python/python/dist/src/Parser
In directory usw-pr-cvs1:/tmp/cvs-serv13045/Parser

Modified Files:
	tokenizer.c 
Log Message:
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
-- replace then with slightly faster PyObject_Call(o,a,NULL).  (The
difference is that the latter requires a to be a tuple; the former
allows other values and wraps them in a tuple if necessary; it
involves two more levels of C function calls to accomplish all that.)


Index: tokenizer.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/tokenizer.c,v
retrieving revision 2.64
retrieving revision 2.65
diff -C2 -d -r2.64 -r2.65
*** tokenizer.c	15 Aug 2002 01:20:16 -0000	2.64
--- tokenizer.c	16 Aug 2002 17:01:09 -0000	2.65
***************
*** 328,337 ****
  	/* In a non-Unicode built, this should never be called. */
  	Py_FatalError("fp_readl should not be called in this build.");
! 	return NULL;
  #else
  	PyObject* utf8;
  	PyObject* buf = tok->decoding_buffer;
  	if (buf == NULL) {
! 		buf = PyObject_CallObject(tok->decoding_readline, NULL);
  		if (buf == NULL)
  			return error_ret(tok);
--- 328,341 ----
  	/* In a non-Unicode built, this should never be called. */
  	Py_FatalError("fp_readl should not be called in this build.");
! 	return NULL; /* Keep compiler happy (not reachable) */
  #else
  	PyObject* utf8;
  	PyObject* buf = tok->decoding_buffer;
  	if (buf == NULL) {
! 		PyObject *args = PyTuple_New(0);
! 		if (args == NULL)
! 			return error_ret(tok);
! 		buf = PyObject_Call(tok->decoding_readline, args, NULL);
! 		Py_DECREF(args);
  		if (buf == NULL)
  			return error_ret(tok);
***************
*** 465,469 ****
  		PyObject* buf = tok->decoding_buffer;
  		if (buf == NULL) {
! 			buf = PyObject_CallObject(tok->decoding_readline, NULL);
  			if (buf == NULL) {
  				error_ret(tok);
--- 469,480 ----
  		PyObject* buf = tok->decoding_buffer;
  		if (buf == NULL) {
! 			PyObject *args = PyTuple_New(0);
! 			if (args == NULL) {
! 				error_ret(tok);
! 				return 1;
! 			}
! 			buf = PyObject_Call(tok->decoding_readline,
! 					    args, NULL);
! 			Py_DECREF(args);
  			if (buf == NULL) {
  				error_ret(tok);