mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
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.
This commit is contained in:
parent
1cb7aa3e6e
commit
25916bdc11
1 changed files with 25 additions and 19 deletions
|
@ -80,44 +80,50 @@ vgetargs1(PyObject *args, char *format, va_list *p_va, int compat)
|
||||||
int min = -1;
|
int min = -1;
|
||||||
int max = 0;
|
int max = 0;
|
||||||
int level = 0;
|
int level = 0;
|
||||||
|
int endfmt = 0;
|
||||||
char *formatsave = format;
|
char *formatsave = format;
|
||||||
int i, len;
|
int i, len;
|
||||||
char *msg;
|
char *msg;
|
||||||
|
|
||||||
assert(compat || (args != (PyObject*)NULL));
|
assert(compat || (args != (PyObject*)NULL));
|
||||||
|
|
||||||
for (;;) {
|
while (endfmt == 0) {
|
||||||
int c = *format++;
|
int c = *format++;
|
||||||
if (c == '(' /* ')' */) {
|
switch (c) {
|
||||||
|
case '(':
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
max++;
|
max++;
|
||||||
level++;
|
level++;
|
||||||
}
|
break;
|
||||||
else if (/* '(' */ c == ')') {
|
case ')':
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
Py_FatalError(/* '(' */
|
Py_FatalError("excess ')' in getargs format");
|
||||||
"excess ')' in getargs format");
|
|
||||||
else
|
else
|
||||||
level--;
|
level--;
|
||||||
}
|
|
||||||
else if (c == '\0')
|
|
||||||
break;
|
break;
|
||||||
else if (c == ':') {
|
case '\0':
|
||||||
|
endfmt = 1;
|
||||||
|
break;
|
||||||
|
case ':':
|
||||||
fname = format;
|
fname = format;
|
||||||
|
endfmt = 1;
|
||||||
break;
|
break;
|
||||||
}
|
case ';':
|
||||||
else if (c == ';') {
|
|
||||||
message = format;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else if (level != 0)
|
|
||||||
; /* Pass */
|
|
||||||
else if (c == 'e')
|
|
||||||
; /* Pass */
|
|
||||||
else if (isalpha(c))
|
|
||||||
max++;
|
|
||||||
else if (c == '|')
|
|
||||||
min = max;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level != 0)
|
if (level != 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue