Skip to content

Commit 937872e

Browse files
Simplify _PyPegen_join_names_with_dot() (GH-111602)
1 parent 5697fc2 commit 937872e

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

Parser/action_helpers.c

+2-32
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,8 @@ expr_ty
118118
_PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name)
119119
{
120120
assert(first_name != NULL && second_name != NULL);
121-
PyObject *first_identifier = first_name->v.Name.id;
122-
PyObject *second_identifier = second_name->v.Name.id;
123-
124-
const char *first_str = PyUnicode_AsUTF8(first_identifier);
125-
if (!first_str) {
126-
return NULL;
127-
}
128-
const char *second_str = PyUnicode_AsUTF8(second_identifier);
129-
if (!second_str) {
130-
return NULL;
131-
}
132-
Py_ssize_t len = strlen(first_str) + strlen(second_str) + 1; // +1 for the dot
133-
134-
PyObject *str = PyBytes_FromStringAndSize(NULL, len);
135-
if (!str) {
136-
return NULL;
137-
}
138-
139-
char *s = PyBytes_AS_STRING(str);
140-
if (!s) {
141-
return NULL;
142-
}
143-
144-
strcpy(s, first_str);
145-
s += strlen(first_str);
146-
*s++ = '.';
147-
strcpy(s, second_str);
148-
s += strlen(second_str);
149-
*s = '\0';
150-
151-
PyObject *uni = PyUnicode_DecodeUTF8(PyBytes_AS_STRING(str), PyBytes_GET_SIZE(str), NULL);
152-
Py_DECREF(str);
121+
PyObject *uni = PyUnicode_FromFormat("%U.%U",
122+
first_name->v.Name.id, second_name->v.Name.id);
153123
if (!uni) {
154124
return NULL;
155125
}

0 commit comments

Comments
 (0)