* Optimizations

* Reduced memory for attribute and body objects, see `XML_NEW_DIFFERENTIATE` compile-time option.
  * Optimized cbuf handling in parsing and xml2cbuf functions.
  * Optimized xml scanner to read strings rather than single chars
  * Optimized xml_merge for the case of disjunct trees.
This commit is contained in:
Olof hagsand 2020-04-28 22:31:58 +02:00
parent 9a8c6cf3e6
commit 94cf4a88b3
24 changed files with 477 additions and 257 deletions

View file

@ -314,6 +314,7 @@ uri_percent_decode(char *enc,
* ' -> "' " may
* ' -> "" " may
* Optionally >
* @see xml_chardata_cbuf_append for a specialized version
*/
int
xml_chardata_encode(char **escp,
@ -433,6 +434,58 @@ xml_chardata_encode(char **escp,
return retval;
}
/*! Escape characters according to XML definition and append to cbuf
* @param[in] cb CLIgen buf
* @param[in] fmt Not-encoded input string
* @see xml_chardata_encode for the generic function
*/
int
xml_chardata_cbuf_append(cbuf *cb,
char *str)
{
int retval = -1;
int i;
int cdata; /* when set, skip encoding */
/* The orignal of this code is in xml_chardata_encode */
/* Step: encode and expand str --> enc */
/* Same code again, but now actually encode into output buffer */
cdata = 0;
for (i=0; i<strlen(str); i++){
if (cdata){
if (strncmp(&str[i], "]]>", strlen("]]>")) == 0){
cdata = 0;
cbuf_append(cb, str[i++]);
cbuf_append(cb, str[i++]);
}
cbuf_append(cb, str[i]);
}
else
switch (str[i]){
case '&':
cbuf_append_str(cb, "&amp;");
break;
case '<':
if (strncmp(&str[i], "<![CDATA[", strlen("<![CDATA[")) == 0){
cbuf_append(cb, str[i]);
cdata++;
break;
}
cbuf_append_str(cb, "&lt;");
break;
case '>':
cbuf_append_str(cb, "&gt;");
break;
default:
cbuf_append(cb, str[i]);
}
}
retval = 0;
// done:
return retval;
}
/*! Split a string into a cligen variable vector using 1st and 2nd delimiter
* Split a string first into elements delimited by delim1, then into
* pairs delimited by delim2.