[Python-checkins] CVS: python/dist/src/Python getargs.c,2.59,2.60

Jeremy Hylton jhylton@users.sourceforge.net
Tue, 29 May 2001 10:46:21 -0700


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

Modified Files:
	getargs.c 
Log Message:
Change cascaded if stmts to switch stmt in vgetargs1().

In the default branch, keep three ifs that are used if level == 0, the
most common case.  Note that first if here is a slight optimization
for the 'O' format.

Second part of SF patch 426072.


Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.59
retrieving revision 2.60
diff -C2 -r2.59 -r2.60
*** getargs.c	2001/05/29 17:37:05	2.59
--- getargs.c	2001/05/29 17:46:19	2.60
***************
*** 81,84 ****
--- 81,85 ----
  	int max = 0;
  	int level = 0;
+ 	int endfmt = 0;
  	char *formatsave = format;
  	int i, len;
***************
*** 87,122 ****
  	assert(compat || (args != (PyObject*)NULL));
  
! 	for (;;) {
  		int c = *format++;
! 		if (c == '(' /* ')' */) {
  			if (level == 0)
  				max++;
  			level++;
! 		}
! 		else if (/* '(' */ c == ')') {
  			if (level == 0)
! 				Py_FatalError(/* '(' */
! 				      "excess ')' in getargs format");
  			else
  				level--;
- 		}
- 		else if (c == '\0')
  			break;
! 		else if (c == ':') {
  			fname = format;
  			break;
! 		}
! 		else if (c == ';') {
  			message = format;
  			break;
  		}
- 		else if (level != 0)
- 			; /* Pass */
- 		else if (c == 'e')
- 			; /* Pass */
- 		else if (isalpha(c))
- 			max++;
- 		else if (c == '|')
- 			min = max;
  	}
  	
--- 88,128 ----
  	assert(compat || (args != (PyObject*)NULL));
  
! 	while (endfmt == 0) {
  		int c = *format++;
! 		switch (c) {
! 		case '(':
  			if (level == 0)
  				max++;
  			level++;
! 			break;
! 		case ')':
  			if (level == 0)
! 				Py_FatalError("excess ')' in getargs format");
  			else
  				level--;
  			break;
! 		case '\0':
! 			endfmt = 1;
! 			break;
! 		case ':':
  			fname = format;
+ 			endfmt = 1;
  			break;
! 		case ';':
  			message = format;
+ 			endfmt = 1;
+ 			break;
+ 		default:
+ 			if (level == 0) {
+ 				if (c == 'O')
+ 					max++;
+ 				else if (isalpha(c)) {
+ 					if (c != 'e') /* skip encoded */
+ 						max++;
+ 				} else if (c == '|')
+ 					min = max;
+ 			}
  			break;
  		}
  	}