[xml] libxml2 performance xmlParseAttValue



Hi Daniel, All,

Another easy one (perhaps the last and I should start
thinking before coding):

xmlParseAttValue unsurprisingly can profit from
factoring out the easy case, just as already done
for xmlParseName and xmlParseCharData. 

Benefits are pronounced for svg3, but also libxml-api.xml
should gain something like 10%.

This optimization helps most for long attributes as the
costly processing in xmlParseAttValueComplex can
be skipped, but for many small attributes (as in 
libxml-api.xml) the gains are limited by still strnduping.
For these cases xmlParseStartTag should use a
per-document static buffer for all attribute values found
in one start tag, but this will give some major surgery 
in the sources.

Regards,
Peter Jacobi


*** ..\2-4-22\parser.c  Fri May 10 04:35:14 2002
--- parser.c    Fri May 31 10:46:02 2002
***************
*** 2180,2188 ****
--- 2180,2226 ----
   */
  
  xmlChar *
+ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt);
+ 
+ xmlChar *
  xmlParseAttValue(xmlParserCtxtPtr ctxt) {
      xmlChar limit = 0;
      xmlChar *buf = NULL;
+     xmlChar *in = NULL;
+     xmlChar *ret = NULL;
+     SHRINK;
+     GROW;
+     in = CUR_PTR;
+     if (*in != '"' && *in != '\'') {
+       ctxt->errNo = XML_ERR_ATTRIBUTE_NOT_STARTED;
+       if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
+           ctxt->sax->error(ctxt->userData, "AttValue: \" or ' expected\n");
+       ctxt->wellFormed = 0;
+       ctxt->disableSAX = 1;
+       return(NULL);
+     } 
+     ctxt->instate = XML_PARSER_ATTRIBUTE_VALUE;
+     limit = *in;
+     ++in;
+     
+     while (*in != limit && *in >= 0x20 && *in <= 0x7f && 
+       *in != '&' && *in != '<'
+     ) {
+       ++in;
+     }
+     if (*in != limit) {
+       return xmlParseAttValueComplex(ctxt);
+     }
+     ++in;
+     ret = xmlStrndup (CUR_PTR + 1, in - CUR_PTR - 2);
+     CUR_PTR = in;
+     return ret;
+ }
+ 
+ xmlChar *
+ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt) {
+     xmlChar limit = 0;
+     xmlChar *buf = NULL;
      int len = 0;
      int buf_size = 0;
      int c, l;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]