Skip to content

Commit 696d0bd

Browse files
committed
bpo-45045: Optimize mapping patterns of structural pattern matching
1 parent c764dfb commit 696d0bd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Python/ceval.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
859859
if (dummy == NULL) {
860860
goto fail;
861861
}
862-
values = PyList_New(0);
862+
values = PyTuple_New(nkeys);
863863
if (values == NULL) {
864864
goto fail;
865865
}
@@ -873,7 +873,8 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
873873
}
874874
goto fail;
875875
}
876-
PyObject *value = PyObject_CallFunctionObjArgs(get, key, dummy, NULL);
876+
PyObject *args[] = { key, dummy };
877+
PyObject *value = PyObject_Vectorcall(get, args, 2, NULL);
877878
if (value == NULL) {
878879
goto fail;
879880
}
@@ -886,10 +887,8 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys)
886887
values = Py_None;
887888
goto done;
888889
}
889-
PyList_Append(values, value);
890-
Py_DECREF(value);
890+
PyTuple_SET_ITEM(values, i, value);
891891
}
892-
Py_SETREF(values, PyList_AsTuple(values));
893892
// Success:
894893
done:
895894
Py_DECREF(get);

0 commit comments

Comments
 (0)