Cleanup: avoid redundant strlen calls

This commit is contained in:
Campbell Barton
2023-09-20 12:11:33 +10:00
parent e6ef1c36f0
commit fb81c37077
7 changed files with 18 additions and 11 deletions

View File

@@ -242,7 +242,9 @@ static void _build_translations_cache(PyObject *py_messages, const char *locale)
/* Do not overwrite existing keys! */
if (BPY_app_translations_py_pgettext(msgctxt, msgid) == msgid) {
GHashKey *key = _ghashutil_keyalloc(msgctxt, msgid);
BLI_ghash_insert(_translations_cache, key, BLI_strdup(PyUnicode_AsUTF8(trans)));
Py_ssize_t trans_str_len;
const char *trans_str = PyUnicode_AsUTF8AndSize(trans, &trans_str_len);
BLI_ghash_insert(_translations_cache, key, BLI_strdupn(trans_str, trans_str_len));
}
}
}

View File

@@ -33,7 +33,9 @@ static char *pyop_poll_message_get_fn(bContext * /*C*/, void *user_data)
PyObject *py_func_or_msg = PyTuple_GET_ITEM(py_args, 0);
if (PyUnicode_Check(py_func_or_msg)) {
return BLI_strdup(PyUnicode_AsUTF8(py_func_or_msg));
Py_ssize_t msg_len;
const char *msg = PyUnicode_AsUTF8AndSize(py_func_or_msg, &msg_len);
return BLI_strdupn(msg, msg_len);
}
PyObject *py_args_after_first = PyTuple_GetSlice(py_args, 1, PY_SSIZE_T_MAX);
@@ -52,7 +54,9 @@ static char *pyop_poll_message_get_fn(bContext * /*C*/, void *user_data)
/* pass */
}
else if (PyUnicode_Check(py_msg)) {
msg = BLI_strdup(PyUnicode_AsUTF8(py_msg));
Py_ssize_t msg_src_len;
const char *msg_src = PyUnicode_AsUTF8AndSize(py_msg, &msg_src_len);
msg = BLI_strdupn(msg_src, msg_src_len);
}
else {
PyErr_Format(PyExc_TypeError,