aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-12-13 16:29:40 -0500
committerYury Selivanov <yury@magic.io>2018-12-13 16:29:40 -0500
commitdaf67332eeec06f31d6d4fc7ef64c6210a00f830 (patch)
treecdf3b92718b897eb41e2e0b626b9e15b07d7273a
parent9862417e80ada753c85dcc127724843f5c8bc989 (diff)
downloadimmutables-daf67332eeec06f31d6d4fc7ef64c6210a00f830.tar.gz
immutables-daf67332eeec06f31d6d4fc7ef64c6210a00f830.zip
Simplify MapMutation.__exit__() implementation
-rw-r--r--immutables/_map.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/immutables/_map.c b/immutables/_map.c
index 9b406ea..f9c8772 100644
--- a/immutables/_map.c
+++ b/immutables/_map.c
@@ -3819,6 +3819,13 @@ mapmut_set(MapMutationObject *o, PyObject *key, int32_t key_hash,
return 0;
}
+static int
+mapmut_finish(MapMutationObject *o)
+{
+ o->m_mutid = 0;
+ return 0;
+}
+
static PyObject *
mapmut_py_set(MapMutationObject *o, PyObject *args)
{
@@ -3905,9 +3912,11 @@ mapmut_py_update(MapMutationObject *self, PyObject *args, PyObject *kwds)
static PyObject *
-mapmut_py_finalize(MapMutationObject *self, PyObject *args)
+mapmut_py_finish(MapMutationObject *self, PyObject *args)
{
- self->m_mutid = 0;
+ if (mapmut_finish(self)) {
+ return NULL;
+ }
MapObject *o = map_alloc();
if (o == NULL) {
@@ -3931,11 +3940,9 @@ mapmut_py_enter(MapMutationObject *self, PyObject *args)
static PyObject *
mapmut_py_exit(MapMutationObject *self, PyObject *args)
{
- PyObject *ret = mapmut_py_finalize(self, NULL);
- if (ret == NULL) {
+ if (mapmut_finish(self)) {
return NULL;
}
- Py_DECREF(ret);
Py_RETURN_FALSE;
}
@@ -4021,7 +4028,7 @@ static PyMethodDef MapMutation_methods[] = {
{"set", (PyCFunction)mapmut_py_set, METH_VARARGS, NULL},
{"get", (PyCFunction)map_py_get, METH_VARARGS, NULL},
{"pop", (PyCFunction)mapmut_py_pop, METH_VARARGS, NULL},
- {"finish", (PyCFunction)mapmut_py_finalize, METH_NOARGS, NULL},
+ {"finish", (PyCFunction)mapmut_py_finish, METH_NOARGS, NULL},
{"update", (PyCFunction)mapmut_py_update,
METH_VARARGS | METH_KEYWORDS, NULL},
{"__enter__", (PyCFunction)mapmut_py_enter, METH_NOARGS, NULL},