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

Delta Between Two Patch Sets: Modules/_collectionsmodule.c

Issue 29452: Use FASTCALL for collections.deque methods: index, insert, rotate
Left Patch Set: Created 2 years, 6 months ago
Right Patch Set: Created 2 years, 6 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 #include "Python.h" 1 #include "Python.h"
2 #include "structmember.h" 2 #include "structmember.h"
3 3
4 #ifdef STDC_HEADERS 4 #ifdef STDC_HEADERS
5 #include <stddef.h> 5 #include <stddef.h>
6 #else 6 #else
7 #include <sys/types.h> /* For size_t */ 7 #include <sys/types.h> /* For size_t */
8 #endif 8 #endif
9 9
10 /* collections module implementation of a deque() datatype 10 /* collections module implementation of a deque() datatype
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 906
907 return rv; 907 return rv;
908 } 908 }
909 909
910 static PyObject * 910 static PyObject *
911 deque_rotate(dequeobject *deque, PyObject **args, Py_ssize_t nargs, 911 deque_rotate(dequeobject *deque, PyObject **args, Py_ssize_t nargs,
912 PyObject *kwnames) 912 PyObject *kwnames)
913 { 913 {
914 Py_ssize_t n=1; 914 Py_ssize_t n=1;
915 915
916 if (!_PyArg_ParseStack(args, nargs, "|n:rotate", &n))
917 return NULL;
918 if (!_PyArg_NoStackKeywords("rotate", kwnames)) { 916 if (!_PyArg_NoStackKeywords("rotate", kwnames)) {
917 return NULL;
918 }
919 if (!_PyArg_ParseStack(args, nargs, "|n:rotate", &n)) {
919 return NULL; 920 return NULL;
920 } 921 }
921 922
922 if (!_deque_rotate(deque, n)) 923 if (!_deque_rotate(deque, n))
923 Py_RETURN_NONE; 924 Py_RETURN_NONE;
924 return NULL; 925 return NULL;
925 } 926 }
926 927
927 PyDoc_STRVAR(rotate_doc, 928 PyDoc_STRVAR(rotate_doc,
928 "Rotate the deque n steps to the right (default n=1). If n is negative, rotates left."); 929 "Rotate the deque n steps to the right (default n=1). If n is negative, rotates left.");
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 deque_index(dequeobject *deque, PyObject **args, Py_ssize_t nargs, 1051 deque_index(dequeobject *deque, PyObject **args, Py_ssize_t nargs,
1051 PyObject *kwnames) 1052 PyObject *kwnames)
1052 { 1053 {
1053 Py_ssize_t i, n, start=0, stop=Py_SIZE(deque); 1054 Py_ssize_t i, n, start=0, stop=Py_SIZE(deque);
1054 PyObject *v, *item; 1055 PyObject *v, *item;
1055 block *b = deque->leftblock; 1056 block *b = deque->leftblock;
1056 Py_ssize_t index = deque->leftindex; 1057 Py_ssize_t index = deque->leftindex;
1057 size_t start_state = deque->state; 1058 size_t start_state = deque->state;
1058 int cmp; 1059 int cmp;
1059 1060
1061 if (!_PyArg_NoStackKeywords("index", kwnames)) {
1062 return NULL;
1063 }
1060 if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index", &v, 1064 if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index", &v,
1061 _PyEval_SliceIndex, &start, 1065 _PyEval_SliceIndex, &start,
1062 _PyEval_SliceIndex, &stop)) { 1066 _PyEval_SliceIndex, &stop)) {
1063 return NULL;
1064 }
1065 if (!_PyArg_NoStackKeywords("index", kwnames)) {
1066 return NULL; 1067 return NULL;
1067 } 1068 }
1068 1069
1069 if (start < 0) { 1070 if (start < 0) {
1070 start += Py_SIZE(deque); 1071 start += Py_SIZE(deque);
1071 if (start < 0) 1072 if (start < 0)
1072 start = 0; 1073 start = 0;
1073 } 1074 }
1074 if (stop < 0) { 1075 if (stop < 0) {
1075 stop += Py_SIZE(deque); 1076 stop += Py_SIZE(deque);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1130
1130 static PyObject * 1131 static PyObject *
1131 deque_insert(dequeobject *deque, PyObject **args, Py_ssize_t nargs, 1132 deque_insert(dequeobject *deque, PyObject **args, Py_ssize_t nargs,
1132 PyObject *kwnames) 1133 PyObject *kwnames)
1133 { 1134 {
1134 Py_ssize_t index; 1135 Py_ssize_t index;
1135 Py_ssize_t n = Py_SIZE(deque); 1136 Py_ssize_t n = Py_SIZE(deque);
1136 PyObject *value; 1137 PyObject *value;
1137 PyObject *rv; 1138 PyObject *rv;
1138 1139
1139 if (!_PyArg_ParseStack(args, nargs, "nO:insert", &index, &value))
1140 return NULL;
1141 if (!_PyArg_NoStackKeywords("insert", kwnames)) { 1140 if (!_PyArg_NoStackKeywords("insert", kwnames)) {
1141 return NULL;
1142 }
1143 if (!_PyArg_ParseStack(args, nargs, "nO:insert", &index, &value)) {
1142 return NULL; 1144 return NULL;
1143 } 1145 }
1144 1146
1145 if (deque->maxlen == Py_SIZE(deque)) { 1147 if (deque->maxlen == Py_SIZE(deque)) {
1146 PyErr_SetString(PyExc_IndexError, "deque already at its maximum size"); 1148 PyErr_SetString(PyExc_IndexError, "deque already at its maximum size");
1147 return NULL; 1149 return NULL;
1148 } 1150 }
1149 if (index >= n) 1151 if (index >= n)
1150 return deque_append(deque, value); 1152 return deque_append(deque, value);
1151 if (index <= -n || index == 0) 1153 if (index <= -n || index == 0)
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2423 Py_INCREF(&dequeiter_type); 2425 Py_INCREF(&dequeiter_type);
2424 PyModule_AddObject(m, "_deque_iterator", (PyObject *)&dequeiter_type); 2426 PyModule_AddObject(m, "_deque_iterator", (PyObject *)&dequeiter_type);
2425 2427
2426 if (PyType_Ready(&dequereviter_type) < 0) 2428 if (PyType_Ready(&dequereviter_type) < 0)
2427 return NULL; 2429 return NULL;
2428 Py_INCREF(&dequereviter_type); 2430 Py_INCREF(&dequereviter_type);
2429 PyModule_AddObject(m, "_deque_reverse_iterator", (PyObject *)&dequereviter_t ype); 2431 PyModule_AddObject(m, "_deque_reverse_iterator", (PyObject *)&dequereviter_t ype);
2430 2432
2431 return m; 2433 return m;
2432 } 2434 }
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+