Skip to content

Commit 86e730b

Browse files
committed
code cleanup
1 parent 4430b6e commit 86e730b

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

Objects/dictobject.c

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,8 +4162,11 @@ static PySequenceMethods dictkeys_as_sequence = {
41624162
(objobjproc)dictkeys_contains, /* sq_contains */
41634163
};
41644164

4165+
// Create an set object from dictviews object.
4166+
// Returns a new reference.
4167+
// This utility function is used by set operations.
41654168
static PyObject*
4166-
dictviews_sub(PyObject* self, PyObject *other)
4169+
dictviews_to_set(PyObject *self)
41674170
{
41684171
PyObject *left = self;
41694172
if (PyDictKeys_Check(self)) {
@@ -4173,7 +4176,13 @@ dictviews_sub(PyObject* self, PyObject *other)
41734176
left = dict;
41744177
}
41754178
}
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);
41774186
if (result == NULL) {
41784187
return NULL;
41794188
}
@@ -4281,43 +4290,22 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)
42814290
static PyObject*
42824291
dictviews_or(PyObject* self, PyObject *other)
42834292
{
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);
42934294
if (result == NULL) {
42944295
return NULL;
42954296
}
42964297

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) {
43014299
Py_DECREF(result);
43024300
return NULL;
43034301
}
4304-
4305-
Py_DECREF(tmp);
43064302
return result;
43074303
}
43084304

43094305
static PyObject*
43104306
dictviews_xor(PyObject* self, PyObject *other)
43114307
{
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);
43214309
if (result == NULL) {
43224310
return NULL;
43234311
}

0 commit comments

Comments
 (0)