@@ -27,31 +27,20 @@ istr_dealloc(istrobject *self)
27
27
}
28
28
29
29
static inline PyObject *
30
- istr_new_with_state (PyTypeObject * type , PyObject * args , PyObject * kwds ,
31
- mod_state * state )
30
+ istr_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
32
31
{
33
- if (state == NULL ) {
34
- PyObject * mod = PyType_GetModuleByDef (type , & multidict_module );
35
- if (mod == NULL ) {
36
- return NULL ;
37
- }
38
- state = get_mod_state (mod );
32
+ PyObject * mod = PyType_GetModuleByDef (type , & multidict_module );
33
+ if (mod == NULL ) {
34
+ return NULL ;
39
35
}
36
+ mod_state * state = get_mod_state (mod );
40
37
41
38
PyObject * x = NULL ;
42
39
static char * kwlist [] = {"object" , "encoding" , "errors" , 0 };
43
40
PyObject * encoding = NULL ;
44
41
PyObject * errors = NULL ;
45
42
PyObject * canonical = NULL ;
46
- PyObject * ret = NULL ;
47
- if (kwds != NULL ) {
48
- int cmp = PyDict_Pop (kwds , state -> str_canonical , & canonical );
49
- if (cmp < 0 ) {
50
- return NULL ;
51
- } else if (cmp > 0 ) {
52
- Py_INCREF (canonical );
53
- }
54
- }
43
+ PyObject * ret = NULL ;
55
44
56
45
if (!PyArg_ParseTupleAndKeywords (args , kwds , "|OOO:str" ,
57
46
kwlist , & x , & encoding , & errors )) {
@@ -65,20 +54,9 @@ istr_new_with_state(PyTypeObject *type, PyObject *args, PyObject *kwds,
65
54
if (!ret ) {
66
55
goto fail ;
67
56
}
68
-
69
- if (canonical == NULL ) {
70
- canonical = PyObject_CallMethodNoArgs (ret , state -> str_lower );
71
- if (!canonical ) {
72
- goto fail ;
73
- }
74
- }
75
- if (!PyUnicode_CheckExact (canonical )) {
76
- PyObject * tmp = PyUnicode_FromObject (canonical );
77
- Py_CLEAR (canonical );
78
- if (tmp == NULL ) {
79
- goto fail ;
80
- }
81
- canonical = tmp ;
57
+ canonical = PyObject_CallMethodNoArgs (ret , state -> str_lower );
58
+ if (!canonical ) {
59
+ goto fail ;
82
60
}
83
61
((istrobject * )ret )-> canonical = canonical ;
84
62
((istrobject * )ret )-> state = state ;
@@ -88,12 +66,6 @@ istr_new_with_state(PyTypeObject *type, PyObject *args, PyObject *kwds,
88
66
return NULL ;
89
67
}
90
68
91
- static inline PyObject *
92
- istr_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
93
- {
94
- return istr_new_with_state (type , args , kwds , NULL );
95
- }
96
-
97
69
static inline PyObject *
98
70
istr_reduce (PyObject * self )
99
71
{
@@ -147,33 +119,20 @@ static inline PyObject *
147
119
IStr_New (mod_state * state , PyObject * str , PyObject * canonical )
148
120
{
149
121
PyObject * args = NULL ;
150
- PyObject * kwds = NULL ;
151
122
PyObject * res = NULL ;
152
-
153
123
args = PyTuple_Pack (1 , str );
154
124
if (args == NULL ) {
155
125
goto ret ;
156
126
}
157
-
158
- if (canonical != NULL ) {
159
- kwds = PyDict_New ();
160
- if (kwds == NULL ) {
161
- goto ret ;
162
- }
163
- if (!PyUnicode_CheckExact (canonical )) {
164
- PyErr_SetString (PyExc_TypeError ,
165
- "'canonical' argument should be exactly str" );
166
- goto ret ;
167
- }
168
- if (PyDict_SetItem (kwds , state -> str_canonical , canonical ) < 0 ) {
169
- goto ret ;
170
- }
127
+ res = PyUnicode_Type .tp_new (state -> IStrType , args , NULL );
128
+ if (!res ) {
129
+ goto ret ;
171
130
}
172
-
173
- res = istr_new_with_state (state -> IStrType , args , kwds , state );
131
+ Py_INCREF (canonical );
132
+ ((istrobject * )res )-> canonical = canonical ;
133
+ ((istrobject * )res )-> state = state ;
174
134
ret :
175
135
Py_CLEAR (args );
176
- Py_CLEAR (kwds );
177
136
return res ;
178
137
}
179
138
0 commit comments