@@ -4162,8 +4162,11 @@ static PySequenceMethods dictkeys_as_sequence = {
4162
4162
(objobjproc )dictkeys_contains , /* sq_contains */
4163
4163
};
4164
4164
4165
+ // Create an set object from dictviews object.
4166
+ // Returns a new reference.
4167
+ // This utility function is used by set operations.
4165
4168
static PyObject *
4166
- dictviews_sub (PyObject * self , PyObject * other )
4169
+ dictviews_to_set (PyObject * self )
4167
4170
{
4168
4171
PyObject * left = self ;
4169
4172
if (PyDictKeys_Check (self )) {
@@ -4173,7 +4176,13 @@ dictviews_sub(PyObject* self, PyObject *other)
4173
4176
left = dict ;
4174
4177
}
4175
4178
}
4176
- PyObject * result = PySet_New (left );
4179
+ return PySet_New (left );
4180
+ }
4181
+
4182
+ static PyObject *
4183
+ dictviews_sub (PyObject * self , PyObject * other )
4184
+ {
4185
+ PyObject * result = dictviews_to_set (self );
4177
4186
if (result == NULL ) {
4178
4187
return NULL ;
4179
4188
}
@@ -4281,43 +4290,22 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)
4281
4290
static PyObject *
4282
4291
dictviews_or (PyObject * self , PyObject * other )
4283
4292
{
4284
- PyObject * left = self ;
4285
- if (PyDictKeys_Check (self )) {
4286
- // PySet_New() has fast path for the dict object.
4287
- PyObject * dict = (PyObject * )((_PyDictViewObject * )self )-> dv_dict ;
4288
- if (PyDict_CheckExact (dict )) {
4289
- left = dict ;
4290
- }
4291
- }
4292
- PyObject * result = PySet_New (left );
4293
+ PyObject * result = dictviews_to_set (self );
4293
4294
if (result == NULL ) {
4294
4295
return NULL ;
4295
4296
}
4296
4297
4297
- _Py_IDENTIFIER (update );
4298
- PyObject * tmp = _PyObject_CallMethodIdOneArg (
4299
- result , & PyId_update , other );
4300
- if (tmp == NULL ) {
4298
+ if (_PySet_Update (result , other ) < 0 ) {
4301
4299
Py_DECREF (result );
4302
4300
return NULL ;
4303
4301
}
4304
-
4305
- Py_DECREF (tmp );
4306
4302
return result ;
4307
4303
}
4308
4304
4309
4305
static PyObject *
4310
4306
dictviews_xor (PyObject * self , PyObject * other )
4311
4307
{
4312
- PyObject * left = self ;
4313
- if (PyDictKeys_Check (self )) {
4314
- // PySet_New() has fast path for the dict object.
4315
- PyObject * dict = (PyObject * )((_PyDictViewObject * )self )-> dv_dict ;
4316
- if (PyDict_CheckExact (dict )) {
4317
- left = dict ;
4318
- }
4319
- }
4320
- PyObject * result = PySet_New (left );
4308
+ PyObject * result = dictviews_to_set (self );
4321
4309
if (result == NULL ) {
4322
4310
return NULL ;
4323
4311
}
0 commit comments