You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sh...@apache.org on 2009/09/09 07:08:06 UTC

svn commit: r812771 - in /webservices/axis2/trunk/c/guththila/src: guththila_xml_parser.c guththila_xml_writer.c

Author: shankar
Date: Wed Sep  9 05:08:05 2009
New Revision: 812771

URL: http://svn.apache.org/viewvc?rev=812771&view=rev
Log:
improving performance

Modified:
    webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c
    webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c

Modified: webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c?rev=812771&r1=812770&r2=812771&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c (original)
+++ webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c Wed Sep  9 05:08:05 2009
@@ -31,14 +31,6 @@
     guththila_t * m,
     const axutil_env_t * env);
 
-/*
- * Read until finding '<' character
- */
-static int
-guththila_search_for_start_element(
-    guththila_t *m,
-    const axutil_env_t *env);
-
 /* part of guththila_next_char method. this was included as macro for performance. 99% of the time
  * following will be called, so having it as next_char method is very expensive (method calling
  * overhead is higher) so, common case is checked as part of the macro and if not satisfied, method
@@ -451,10 +443,20 @@
 {
     size_t size = tok->size;
     guththila_char_t *start = tok->start;
+    guththila_char_t *pos = NULL;
     size_t i, j;
 
-    for(i = 0; (i < size) && (start[i] != '&'); i++)
-        ;
+    pos = (guththila_char_t *)memchr(start, '&', size);
+    if(pos)
+    {
+        i = pos - start;
+    }
+    else
+    {
+        i = size;
+    }
+    /*for(i = 0; (i < size) && (start[i] != '&'); i++)
+        ;*/
     if(i < size)
     {
         j = i;
@@ -1093,10 +1095,27 @@
                 {
                     do
                     {
-                        /*GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);*/
-                        c = guththila_search_for_start_element(m, env);
-                    }
-                    while((c != '<') && (c >= 0));
+                        if(buffer)
+                        {
+                            guththila_char_t *pos = NULL;
+                            int index = m->next - previous_size;
+                            pos = (guththila_char_t*)memchr(buffer + index, '<', data_size - index);
+                            if(pos)
+                            {
+                                m->next += pos - (buffer + index);
+                            }
+                            else
+                            {
+                                m->next = previous_size + data_size;
+                            }
+
+                            GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
+                        }
+                        else
+                        {
+                            GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
+                        }
+                    }while((c != '<') && (c >= 0));
                 }
             }
             while((c != '<') && (c >= 0));
@@ -1815,41 +1834,3 @@
     }
     return -1;
 }
-
-static int
-guththila_search_for_start_element(
-    guththila_t *m,
-    const axutil_env_t *env)
-{
-    guththila_char_t *buffer = NULL;
-    int data_size = -1;
-    int previous_size = -1;
-
-    int c;
-    do
-    {
-        if(buffer)
-        {
-            guththila_char_t *pos = NULL;
-            int index = m->next - previous_size;
-            pos = (guththila_char_t*)memchr(buffer + index, '<', data_size - index);
-            if(pos)
-            {
-                m->next += pos - (buffer + index);
-            }
-            else
-            {
-                m->next = previous_size + data_size;
-            }
-
-            GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
-        }
-        else
-        {
-            GUTHTHILA_NEXT_CHAR(m, buffer, data_size, previous_size, env, c);
-        }
-    }while((c != '<') && (c >= 0));
-
-    return c;
-}
-

Modified: webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c?rev=812771&r1=812770&r2=812771&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c (original)
+++ webservices/axis2/trunk/c/guththila/src/guththila_xml_writer.c Wed Sep  9 05:08:05 2009
@@ -725,9 +725,7 @@
     guththila_char_t *buff,
     const axutil_env_t * env)
 {
-    size_t i = 0;
     size_t len = strlen(buff);
-    guththila_char_t ch = 0;
     if(wr->status == START)
     {
         wr->status = BEGINING;
@@ -745,10 +743,19 @@
     }
     while(len > 0)
     {
-        /* scan buffer until the next special character */
-        for(i = 0; (i < len) && ((ch = buff[i]) != '&') && (ch != '<') && (ch != '>') && (ch
-            != '\"') && (ch != '\''); i++)
-            ;
+        size_t i = 0;
+        /* scan buffer until the next special character (&, <, >, ', ") these need to be escaped,
+         * otherwise XML will not be valid*/
+        guththila_char_t *pos = (guththila_char_t*)strpbrk(buff, "&<>'\"");
+        if(pos)
+        {
+            i = pos - buff;
+        }
+        else
+        {
+            i = len;
+        }
+
         /* write everything until the special character */
         if(i > 0)
         {