Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b52ad5

Browse files
authored
Merge pull request #16393 from anntzer/get_charmap
Shorten PyFT2Font_get_charmap.
2 parents 29fe439 + f316634 commit 2b52ad5

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

src/ft2font_wrapper.cpp

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -975,44 +975,24 @@ const char *PyFT2Font_get_charmap__doc__ =
975975
static PyObject *PyFT2Font_get_charmap(PyFT2Font *self, PyObject *args, PyObject *kwds)
976976
{
977977
PyObject *charmap;
978-
979-
charmap = PyDict_New();
980-
if (charmap == NULL) {
978+
if (!(charmap = PyDict_New())) {
981979
return NULL;
982980
}
983-
984981
FT_UInt index;
985982
FT_ULong code = FT_Get_First_Char(self->x->get_face(), &index);
986983
while (index != 0) {
987-
PyObject *key;
988-
PyObject *val;
989-
990-
key = PyLong_FromLong(code);
991-
if (key == NULL) {
992-
Py_DECREF(charmap);
993-
return NULL;
994-
}
995-
996-
val = PyLong_FromLong(index);
997-
if (val == NULL) {
998-
Py_DECREF(key);
999-
Py_DECREF(charmap);
1000-
return NULL;
1001-
}
1002-
1003-
if (PyDict_SetItem(charmap, key, val)) {
1004-
Py_DECREF(key);
1005-
Py_DECREF(val);
984+
PyObject *key = NULL, *val = NULL;
985+
bool error = (!(key = PyLong_FromLong(code))
986+
|| !(val = PyLong_FromLong(index))
987+
|| (PyDict_SetItem(charmap, key, val) == -1));
988+
Py_XDECREF(key);
989+
Py_XDECREF(val);
990+
if (error) {
1006991
Py_DECREF(charmap);
1007992
return NULL;
1008993
}
1009-
1010-
Py_DECREF(key);
1011-
Py_DECREF(val);
1012-
1013994
code = FT_Get_Next_Char(self->x->get_face(), code, &index);
1014995
}
1015-
1016996
return charmap;
1017997
}
1018998

0 commit comments

Comments
 (0)