Skip to content

Commit 677c7fe

Browse files
committed
xml: Migrate start_element_handler_ns to ZendMM
1 parent e0561f0 commit 677c7fe

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

ext/xml/compat.c

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -93,63 +93,57 @@ start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix,
9393

9494
if (parser->h_start_element == NULL) {
9595
if (parser->h_default) {
96-
96+
smart_string qualified_name = {0};
97+
smart_string_appendc(&qualified_name, '<');
9798
if (prefix) {
98-
qualified_name = xmlStrncatNew((xmlChar *)"<", prefix, xmlStrlen(prefix));
99-
qualified_name = xmlStrncat(qualified_name, (xmlChar *)":", 1);
100-
qualified_name = xmlStrncat(qualified_name, name, xmlStrlen(name));
101-
} else {
102-
qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name));
99+
smart_string_appends(&qualified_name, (const char *) prefix);
100+
smart_string_appendc(&qualified_name, ':');
103101
}
102+
smart_string_appends(&qualified_name, (const char *) name);
104103

105104
if (namespaces) {
106105
int i, j;
107106
for (i = 0,j = 0;j < nb_namespaces;j++) {
108-
int ns_len;
109-
char *ns_string, *ns_prefix, *ns_url;
110-
111-
ns_prefix = (char *) namespaces[i++];
112-
ns_url = (char *) namespaces[i++];
107+
const char *ns_prefix = (const char *) namespaces[i++];
108+
const char *ns_url = (const char *) namespaces[i++];
113109

114110
if (ns_prefix) {
115-
ns_len = spprintf(&ns_string, 0, " xmlns:%s=\"%s\"", ns_prefix, ns_url);
111+
smart_string_appends(&qualified_name, " xmlns:");
112+
smart_string_appends(&qualified_name, ns_prefix);
113+
smart_string_appends(&qualified_name, "=\"");
116114
} else {
117-
ns_len = spprintf(&ns_string, 0, " xmlns=\"%s\"", ns_url);
115+
smart_string_appends(&qualified_name, " xmlns=\"");
118116
}
119-
qualified_name = xmlStrncat(qualified_name, (xmlChar *)ns_string, ns_len);
120117

121-
efree(ns_string);
118+
smart_string_appends(&qualified_name, ns_url);
119+
smart_string_appendc(&qualified_name, '"');
122120
}
123121
}
124122

125123
if (attributes) {
126124
for (i = 0; i < nb_attributes; i += 1) {
127-
int att_len;
128-
char *att_string, *att_name, *att_value, *att_prefix, *att_valueend;
129-
130-
att_name = (char *) attributes[y++];
131-
att_prefix = (char *)attributes[y++];
125+
const char *att_name = (const char *) attributes[y++];
126+
const char *att_prefix = (const char *)attributes[y++];
132127
y++;
133-
att_value = (char *)attributes[y++];
134-
att_valueend = (char *)attributes[y++];
128+
const char *att_value = (const char *)attributes[y++];
129+
const char *att_valueend = (const char *)attributes[y++];
135130

131+
smart_string_appendc(&qualified_name, ' ');
136132
if (att_prefix) {
137-
att_len = spprintf(&att_string, 0, " %s:%s=\"", att_prefix, att_name);
138-
} else {
139-
att_len = spprintf(&att_string, 0, " %s=\"", att_name);
133+
smart_string_appends(&qualified_name, att_prefix);
134+
smart_string_appendc(&qualified_name, ':');
140135
}
136+
smart_string_appends(&qualified_name, att_name);
137+
smart_string_appends(&qualified_name, "=\"");
141138

142-
qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len);
143-
qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_value, att_valueend - att_value);
144-
qualified_name = xmlStrncat(qualified_name, (xmlChar *)"\"", 1);
145-
146-
efree(att_string);
139+
smart_string_appendl(&qualified_name, att_value, att_valueend - att_value);
140+
smart_string_appendc(&qualified_name, '"');
147141
}
148142

149143
}
150-
qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1);
151-
parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name));
152-
xmlFree(qualified_name);
144+
smart_string_appendc(&qualified_name, '>');
145+
parser->h_default(parser->user, (const XML_Char *) qualified_name.c, qualified_name.len);
146+
smart_string_free(&qualified_name);
153147
}
154148
return;
155149
}

0 commit comments

Comments
 (0)