[xml] ctxt->token patches



Hi Daniel, All,

Find attached patches for removing ctxt->token
usage in parser.c and parserInternals.c

As a previous patch successfully eliminated
all non-zero assignments to ctxt->token, in theory 
all uses of ctxt->token can be removed.

But at some places, removal of this
code make performance worse (must
be cache line alignment, cache preload
or static branch prediction).

So I tried to find the removals which 
enhance performance and now get a
performance gain of 7% for api.xml
on slow x86 (200Mhz PPro).

Regards,
Peter Jacobi


*** baseline\parserinternals.c  Thu Mar 21 08:31:14 2002
--- parserinternals.c   Fri Jun 28 10:23:45 2002
***************
*** 1260,1269 ****
      if (ctxt->instate == XML_PARSER_EOF)
        return(0);
  
-     if (ctxt->token != 0) {
-       *len = 0;
-       return(ctxt->token);
-     } 
      if ((*ctxt->input->cur >= 0x20) && (*ctxt->input->cur <= 0x7F)) {
            *len = 1;
            return((int) *ctxt->input->cur);
--- 1260,1265 ----
*** baseline\parser.c   Sat Jun 15 09:32:20 2002
--- parser.c    Fri Jun 28 12:48:06 2002
***************
*** 268,275 ****
   *   GROW, SHRINK  handling of input buffers
   */
  
! #define RAW (ctxt->token ? -1 : (*ctxt->input->cur))
! #define CUR (ctxt->token ? ctxt->token : (*ctxt->input->cur))
  #define NXT(val) ctxt->input->cur[(val)]
  #define CUR_PTR ctxt->input->cur
  
--- 268,275 ----
   *   GROW, SHRINK  handling of input buffers
   */
  
! #define RAW (*ctxt->input->cur)
! #define CUR (*ctxt->input->cur)
  #define NXT(val) ctxt->input->cur[(val)]
  #define CUR_PTR ctxt->input->cur
  
***************
*** 2366,2394 ****
      while (((NXT(0) != limit) && /* checked */
           (c != '<')) || (ctxt->token != 0)) {
        if (c == 0) break;
!       if (ctxt->token == '&') {
!           if (ctxt->replaceEntities) {
!               if (len > buf_size - 10) {
!                   growBuffer(buf);
!               }
!               buf[len++] = '&';
!           } else {
!               /*
!                * The reparsing will be done in xmlStringGetNodeList()
!                * called by the attribute() function in SAX.c
!                */
!               static xmlChar buffer[6] = "&#38;";
! 
!               if (len > buf_size - 10) {
!                   growBuffer(buf);
!               }
!               current = &buffer[0];
!               while (*current != 0) { /* non input consuming */
!                   buf[len++] = *current++;
!               }
!               ctxt->token = 0;
!           }
!       } else if (c == '&') {
            if (NXT(1) == '#') {
                int val = xmlParseCharRef(ctxt);
                if (val == '&') {
--- 2366,2372 ----
      while (((NXT(0) != limit) && /* checked */
           (c != '<')) || (ctxt->token != 0)) {
        if (c == 0) break;
!       if (c == '&') {
            if (NXT(1) == '#') {
                int val = xmlParseCharRef(ctxt);
                if (val == '&') {
***************
*** 6884,6894 ****
  void
  xmlParseContent(xmlParserCtxtPtr ctxt) {
      GROW;
!     while (((RAW != 0) || (ctxt->token != 0)) &&
           ((RAW != '<') || (NXT(1) != '/'))) {
        const xmlChar *test = CUR_PTR;
        int cons = ctxt->input->consumed;
-       int tok = ctxt->token;
        const xmlChar *cur = ctxt->input->cur;
  
        /*
--- 6862,6871 ----
  void
  xmlParseContent(xmlParserCtxtPtr ctxt) {
      GROW;
!     while ((RAW != 0) &&
           ((RAW != '<') || (NXT(1) != '/'))) {
        const xmlChar *test = CUR_PTR;
        int cons = ctxt->input->consumed;
        const xmlChar *cur = ctxt->input->cur;
  
        /*
***************
*** 6955,6962 ****
            xmlPopInput(ctxt);
        SHRINK;
  
!       if ((cons == ctxt->input->consumed) && (test == CUR_PTR) &&
!           (tok == ctxt->token)) {
            ctxt->errNo = XML_ERR_INTERNAL_ERROR;
            if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
                ctxt->sax->error(ctxt->userData,
--- 6932,6938 ----
            xmlPopInput(ctxt);
        SHRINK;
  
!       if ((cons == ctxt->input->consumed) && (test == CUR_PTR)) {
            ctxt->errNo = XML_ERR_INTERNAL_ERROR;
            if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
                ctxt->sax->error(ctxt->userData,

Attachment: ctxt-token-patch-1.zip
Description: Zip archive



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