Skip to content

Commit daf6733

Browse files
committed
Simplify MapMutation.__exit__() implementation
1 parent 9862417 commit daf6733

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

immutables/_map.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,6 +3819,13 @@ mapmut_set(MapMutationObject *o, PyObject *key, int32_t key_hash,
38193819
return 0;
38203820
}
38213821

3822+
static int
3823+
mapmut_finish(MapMutationObject *o)
3824+
{
3825+
o->m_mutid = 0;
3826+
return 0;
3827+
}
3828+
38223829
static PyObject *
38233830
mapmut_py_set(MapMutationObject *o, PyObject *args)
38243831
{
@@ -3905,9 +3912,11 @@ mapmut_py_update(MapMutationObject *self, PyObject *args, PyObject *kwds)
39053912

39063913

39073914
static PyObject *
3908-
mapmut_py_finalize(MapMutationObject *self, PyObject *args)
3915+
mapmut_py_finish(MapMutationObject *self, PyObject *args)
39093916
{
3910-
self->m_mutid = 0;
3917+
if (mapmut_finish(self)) {
3918+
return NULL;
3919+
}
39113920

39123921
MapObject *o = map_alloc();
39133922
if (o == NULL) {
@@ -3931,11 +3940,9 @@ mapmut_py_enter(MapMutationObject *self, PyObject *args)
39313940
static PyObject *
39323941
mapmut_py_exit(MapMutationObject *self, PyObject *args)
39333942
{
3934-
PyObject *ret = mapmut_py_finalize(self, NULL);
3935-
if (ret == NULL) {
3943+
if (mapmut_finish(self)) {
39363944
return NULL;
39373945
}
3938-
Py_DECREF(ret);
39393946
Py_RETURN_FALSE;
39403947
}
39413948

@@ -4021,7 +4028,7 @@ static PyMethodDef MapMutation_methods[] = {
40214028
{"set", (PyCFunction)mapmut_py_set, METH_VARARGS, NULL},
40224029
{"get", (PyCFunction)map_py_get, METH_VARARGS, NULL},
40234030
{"pop", (PyCFunction)mapmut_py_pop, METH_VARARGS, NULL},
4024-
{"finish", (PyCFunction)mapmut_py_finalize, METH_NOARGS, NULL},
4031+
{"finish", (PyCFunction)mapmut_py_finish, METH_NOARGS, NULL},
40254032
{"update", (PyCFunction)mapmut_py_update,
40264033
METH_VARARGS | METH_KEYWORDS, NULL},
40274034
{"__enter__", (PyCFunction)mapmut_py_enter, METH_NOARGS, NULL},

0 commit comments

Comments
 (0)