summaryrefslogtreecommitdiffstats
path: root/Parser/action_helpers.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-11-01 14:25:36 (GMT)
committerGitHub <noreply@github.com>2023-11-01 14:25:36 (GMT)
commit937872e8ea740e22ff571eec474e38312e09bd68 (patch)
tree1a3eab247f7e59fe0849607e74569a303b0997a5 /Parser/action_helpers.c
parent5697fc2d4bff000b2b1dac493d45872ca648490b (diff)
downloadcpython-937872e8ea740e22ff571eec474e38312e09bd68.zip
cpython-937872e8ea740e22ff571eec474e38312e09bd68.tar.gz
cpython-937872e8ea740e22ff571eec474e38312e09bd68.tar.bz2
Simplify _PyPegen_join_names_with_dot() (GH-111602)
Diffstat (limited to 'Parser/action_helpers.c')
-rw-r--r--Parser/action_helpers.c34
1 files changed, 2 insertions, 32 deletions
diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c
index fb2d56a..3f6c282 100644
--- a/Parser/action_helpers.c
+++ b/Parser/action_helpers.c
@@ -118,38 +118,8 @@ expr_ty
_PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name)
{
assert(first_name != NULL && second_name != NULL);
- PyObject *first_identifier = first_name->v.Name.id;
- PyObject *second_identifier = second_name->v.Name.id;
-
- const char *first_str = PyUnicode_AsUTF8(first_identifier);
- if (!first_str) {
- return NULL;
- }
- const char *second_str = PyUnicode_AsUTF8(second_identifier);
- if (!second_str) {
- return NULL;
- }
- Py_ssize_t len = strlen(first_str) + strlen(second_str) + 1; // +1 for the dot
-
- PyObject *str = PyBytes_FromStringAndSize(NULL, len);
- if (!str) {
- return NULL;
- }
-
- char *s = PyBytes_AS_STRING(str);
- if (!s) {
- return NULL;
- }
-
- strcpy(s, first_str);
- s += strlen(first_str);
- *s++ = '.';
- strcpy(s, second_str);
- s += strlen(second_str);
- *s = '\0';
-
- PyObject *uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str), PyBytes_GET_SIZE(str), NULL);
- Py_DECREF(str);
+ PyObject *uni = PyUnicode_FromFormat("%U.%U",
+ first_name->v.Name.id, second_name->v.Name.id);
if (!uni) {
return NULL;
}