Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(33210)

Delta Between Two Patch Sets: Python/getargs.c

Issue 29029: Faster positional arguments parsing in PyArg_ParseTupleAndKeywords
Left Patch Set: Created 2 years, 6 months ago
Right Patch Set: Created 2 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 1
2 /* New getargs implementation */ 2 /* New getargs implementation */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 5
6 #include <ctype.h> 6 #include <ctype.h>
7 7
8 8
9 #ifdef __cplusplus 9 #ifdef __cplusplus
10 extern "C" { 10 extern "C" {
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 return retval; 1446 return retval;
1447 } 1447 }
1448 1448
1449 int 1449 int
1450 _PyArg_ParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords, 1450 _PyArg_ParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
1451 struct _PyArg_Parser *parser, ...) 1451 struct _PyArg_Parser *parser, ...)
1452 { 1452 {
1453 int retval; 1453 int retval;
1454 va_list va; 1454 va_list va;
1455 1455
1456 if ((args == NULL || !PyTuple_Check(args)) ||
1457 (keywords != NULL && !PyDict_Check(keywords)) ||
1458 parser == NULL)
1459 {
1460 PyErr_BadInternalCall();
1461 return 0;
1462 }
1463
1464 va_start(va, parser); 1456 va_start(va, parser);
1465 retval = vgetargskeywordsfast(args, keywords, parser, &va, 0); 1457 retval = vgetargskeywordsfast(args, keywords, parser, &va, 0);
1466 va_end(va); 1458 va_end(va);
1467 return retval; 1459 return retval;
1468 } 1460 }
1469 1461
1470 int 1462 int
1471 _PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords, 1463 _PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
1472 struct _PyArg_Parser *parser, ...) 1464 struct _PyArg_Parser *parser, ...)
1473 { 1465 {
1474 int retval; 1466 int retval;
1475 va_list va; 1467 va_list va;
1476 1468
1477 if ((args == NULL || !PyTuple_Check(args)) ||
1478 (keywords != NULL && !PyDict_Check(keywords)) ||
1479 parser == NULL)
1480 {
1481 PyErr_BadInternalCall();
1482 return 0;
1483 }
1484
1485 va_start(va, parser); 1469 va_start(va, parser);
1486 retval = vgetargskeywordsfast(args, keywords, parser, &va, FLAG_SIZE_T); 1470 retval = vgetargskeywordsfast(args, keywords, parser, &va, FLAG_SIZE_T);
1487 va_end(va); 1471 va_end(va);
1488 return retval; 1472 return retval;
1489 } 1473 }
1490 1474
1491 int 1475 int
1492 _PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, 1476 _PyArg_ParseStack(PyObject **args, Py_ssize_t nargs, PyObject *kwnames,
1493 struct _PyArg_Parser *parser, ...) 1477 struct _PyArg_Parser *parser, ...)
1494 { 1478 {
1495 int retval; 1479 int retval;
1496 va_list va; 1480 va_list va;
1497 1481
1498 if ((kwnames != NULL && !PyTuple_Check(kwnames)) ||
1499 parser == NULL)
1500 {
1501 PyErr_BadInternalCall();
1502 return 0;
1503 }
1504
1505 va_start(va, parser); 1482 va_start(va, parser);
1506 retval = vgetargskeywordsfast_impl(args, nargs, NULL, kwnames, parser, &va, 0); 1483 retval = vgetargskeywordsfast_impl(args, nargs, NULL, kwnames, parser, &va, 0);
1507 va_end(va); 1484 va_end(va);
1508 return retval; 1485 return retval;
1509 } 1486 }
1510 1487
1511 int 1488 int
1512 _PyArg_ParseStack_SizeT(PyObject **args, Py_ssize_t nargs, PyObject *kwnames, 1489 _PyArg_ParseStack_SizeT(PyObject **args, Py_ssize_t nargs, PyObject *kwnames,
1513 struct _PyArg_Parser *parser, ...) 1490 struct _PyArg_Parser *parser, ...)
1514 { 1491 {
1515 int retval; 1492 int retval;
1516 va_list va; 1493 va_list va;
1517 1494
1518 if ((kwnames != NULL && !PyTuple_Check(kwnames)) ||
1519 parser == NULL)
1520 {
1521 PyErr_BadInternalCall();
1522 return 0;
1523 }
1524
1525 va_start(va, parser); 1495 va_start(va, parser);
1526 retval = vgetargskeywordsfast_impl(args, nargs, NULL, kwnames, parser, &va, FLAG_SIZE_T); 1496 retval = vgetargskeywordsfast_impl(args, nargs, NULL, kwnames, parser, &va, FLAG_SIZE_T);
1527 va_end(va); 1497 va_end(va);
1528 return retval; 1498 return retval;
1529 } 1499 }
1530 1500
1531 1501
1532 int 1502 int
1533 _PyArg_VaParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords, 1503 _PyArg_VaParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
1534 struct _PyArg_Parser *parser, va_list va) 1504 struct _PyArg_Parser *parser, va_list va)
1535 { 1505 {
1536 int retval; 1506 int retval;
1537 va_list lva; 1507 va_list lva;
1538 1508
1539 if ((args == NULL || !PyTuple_Check(args)) ||
1540 (keywords != NULL && !PyDict_Check(keywords)) ||
1541 parser == NULL)
1542 {
1543 PyErr_BadInternalCall();
1544 return 0;
1545 }
1546
1547 va_copy(lva, va); 1509 va_copy(lva, va);
1548 1510
1549 retval = vgetargskeywordsfast(args, keywords, parser, &lva, 0); 1511 retval = vgetargskeywordsfast(args, keywords, parser, &lva, 0);
1550 va_end(lva); 1512 va_end(lva);
1551 return retval; 1513 return retval;
1552 } 1514 }
1553 1515
1554 int 1516 int
1555 _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords, 1517 _PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
1556 struct _PyArg_Parser *parser, va_list va) 1518 struct _PyArg_Parser *parser, va_list va)
1557 { 1519 {
1558 int retval; 1520 int retval;
1559 va_list lva; 1521 va_list lva;
1560
1561 if ((args == NULL || !PyTuple_Check(args)) ||
1562 (keywords != NULL && !PyDict_Check(keywords)) ||
1563 parser == NULL)
1564 {
1565 PyErr_BadInternalCall();
1566 return 0;
1567 }
1568 1522
1569 va_copy(lva, va); 1523 va_copy(lva, va);
1570 1524
1571 retval = vgetargskeywordsfast(args, keywords, parser, &lva, FLAG_SIZE_T); 1525 retval = vgetargskeywordsfast(args, keywords, parser, &lva, FLAG_SIZE_T);
1572 va_end(lva); 1526 va_end(lva);
1573 return retval; 1527 return retval;
1574 } 1528 }
1575 1529
1576 int 1530 int
1577 PyArg_ValidateKeywordArguments(PyObject *kwargs) 1531 PyArg_ValidateKeywordArguments(PyObject *kwargs)
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 PyObject *current_arg; 1963 PyObject *current_arg;
2010 freelistentry_t static_entries[STATIC_FREELIST_ENTRIES]; 1964 freelistentry_t static_entries[STATIC_FREELIST_ENTRIES];
2011 freelist_t freelist; 1965 freelist_t freelist;
2012 PyObject **kwstack = NULL; 1966 PyObject **kwstack = NULL;
2013 1967
2014 freelist.entries = static_entries; 1968 freelist.entries = static_entries;
2015 freelist.first_available = 0; 1969 freelist.first_available = 0;
2016 freelist.entries_malloced = 0; 1970 freelist.entries_malloced = 0;
2017 1971
2018 assert(kwargs == NULL || PyDict_Check(kwargs)); 1972 assert(kwargs == NULL || PyDict_Check(kwargs));
2019 assert(kwnames == NULL || PyTuple_Check(kwnames));
2020 assert(kwargs == NULL || kwnames == NULL); 1973 assert(kwargs == NULL || kwnames == NULL);
2021 assert(parser != NULL);
2022 assert(p_va != NULL); 1974 assert(p_va != NULL);
1975
1976 if (parser == NULL) {
1977 PyErr_BadInternalCall();
1978 return 0;
1979 }
1980
1981 if (kwnames != NULL && !PyTuple_Check(kwnames)) {
1982 PyErr_BadInternalCall();
1983 return 0;
1984 }
2023 1985
2024 if (!parser_init(parser)) { 1986 if (!parser_init(parser)) {
2025 return 0; 1987 return 0;
2026 } 1988 }
2027 1989
2028 kwtuple = parser->kwtuple; 1990 kwtuple = parser->kwtuple;
2029 pos = parser->pos; 1991 pos = parser->pos;
2030 len = pos + PyTuple_GET_SIZE(kwtuple); 1992 len = pos + PyTuple_GET_SIZE(kwtuple);
2031 1993
2032 if (len > STATIC_FREELIST_ENTRIES) { 1994 if (len > STATIC_FREELIST_ENTRIES) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 return cleanreturn(1, &freelist); 2147 return cleanreturn(1, &freelist);
2186 } 2148 }
2187 2149
2188 static int 2150 static int
2189 vgetargskeywordsfast(PyObject *args, PyObject *keywords, 2151 vgetargskeywordsfast(PyObject *args, PyObject *keywords,
2190 struct _PyArg_Parser *parser, va_list *p_va, int flags) 2152 struct _PyArg_Parser *parser, va_list *p_va, int flags)
2191 { 2153 {
2192 PyObject **stack; 2154 PyObject **stack;
2193 Py_ssize_t nargs; 2155 Py_ssize_t nargs;
2194 2156
2195 assert(args != NULL && PyTuple_Check(args)); 2157 if (args == NULL
2158 || !PyTuple_Check(args)
2159 || (keywords != NULL && !PyDict_Check(keywords)))
2160 {
2161 PyErr_BadInternalCall();
2162 return 0;
2163 }
2196 2164
2197 stack = &PyTuple_GET_ITEM(args, 0); 2165 stack = &PyTuple_GET_ITEM(args, 0);
2198 nargs = PyTuple_GET_SIZE(args); 2166 nargs = PyTuple_GET_SIZE(args);
2199 return vgetargskeywordsfast_impl(stack, nargs, keywords, NULL, 2167 return vgetargskeywordsfast_impl(stack, nargs, keywords, NULL,
2200 parser, p_va, flags); 2168 parser, p_va, flags);
2201 } 2169 }
2202 2170
2203 2171
2204 static const char * 2172 static const char *
2205 skipitem(const char **p_format, va_list *p_va, int flags) 2173 skipitem(const char **p_format, va_list *p_va, int flags)
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 s->next = NULL; 2412 s->next = NULL;
2445 parser_clear(s); 2413 parser_clear(s);
2446 s = tmp; 2414 s = tmp;
2447 } 2415 }
2448 static_arg_parsers = NULL; 2416 static_arg_parsers = NULL;
2449 } 2417 }
2450 2418
2451 #ifdef __cplusplus 2419 #ifdef __cplusplus
2452 }; 2420 };
2453 #endif 2421 #endif
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+