axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shan...@apache.org
Subject svn commit: r812077 - /webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c
Date Mon, 07 Sep 2009 11:01:38 GMT
Author: shankar
Date: Mon Sep  7 11:01:38 2009
New Revision: 812077

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

Modified:
    webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.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=812077&r1=812076&r2=812077&view=diff
==============================================================================
--- webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c (original)
+++ webservices/axis2/trunk/c/guththila/src/guththila_xml_parser.c Mon Sep  7 11:01:38 2009
@@ -29,9 +29,42 @@
 static int
 guththila_next_char(
     guththila_t * m,
-    int eof,
     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
+ * is called
+ */
+#define GUTHTHILA_NEXT_CHAR(m, reader_type, env, c)\
+{\
+    if(reader_type == GUTHTHILA_MEMORY_READER)\
+    {\
+        int index = m->next++;\
+        if(index < m->buffer.data_size[0])\
+        {\
+            c = m->buffer.buff[0][index];\
+        }\
+        else\
+        {\
+            c = -1;\
+        }\
+    }\
+    else\
+    {\
+        if(m->buffer.cur_buff != -1 && m->next < GUTHTHILA_BUFFER_PRE_DATA_SIZE(m->buffer)\
+            + GUTHTHILA_BUFFER_CURRENT_DATA_SIZE(m->buffer))\
+        {\
+            c = m->buffer.buff[m->buffer.cur_buff][m->next++ - GUTHTHILA_BUFFER_PRE_DATA_SIZE(\
+                m->buffer)];\
+        }\
+        else\
+        {\
+            c = guththila_next_char(m, env);\
+        }\
+    }\
+}
+
 /*
  * Read the specified number of characters at once.
  */
@@ -66,14 +99,14 @@
  * Read characters until all the white spaces are read.
  */
 #ifndef GUTHTHILA_SKIP_SPACES
-#define GUTHTHILA_SKIP_SPACES(m, c, _env)while(0x20 == c || 0x9 == c || 0xD == c || 0xA ==
c){c = guththila_next_char(m, 0, _env);}
+#define GUTHTHILA_SKIP_SPACES(m, c, reader_type, _env)while(0x20 == c || 0x9 == c || 0xD
== c || 0xA == c){GUTHTHILA_NEXT_CHAR(m, reader_type, _env, c);}
 #endif  
 
 /*
  * Read character including new line until a non white space character is met.
  */
 #ifndef GUTHTHILA_SKIP_SPACES_WITH_NEW_LINE
-#define GUTHTHILA_SKIP_SPACES_WITH_NEW_LINE(m, c, _env) while (0x20 == c || 0x9 == c || 0xD
== c || 0xA == c || '\n' == c){c = guththila_next_char(m, 0, _env);}
+#define GUTHTHILA_SKIP_SPACES_WITH_NEW_LINE(m, c, reader_type, _env) while (0x20 == c ||
0x9 == c || 0xD == c || 0xA == c || '\n' == c){GUTHTHILA_NEXT_CHAR(m, reader_type, _env, c);}
 #endif  
 
 #ifndef GUTHTHILA_XML_NAME
@@ -108,11 +141,11 @@
  * Read until we met a = character.
  */
 #ifndef GUTHTHILA_PROCESS_EQU
-#define GUTHTHILA_PROCESS_EQU(m, c, ic, _env)							\
-    GUTHTHILA_SKIP_SPACES(m, c, _env); \
+#define GUTHTHILA_PROCESS_EQU(m, c, ic, reader_type, _env)							\
+    GUTHTHILA_SKIP_SPACES(m, c, reader_type, _env); \
     if (0x3D == c) { \
-    ic = guththila_next_char(m, 0, _env); \
-    GUTHTHILA_SKIP_SPACES(m, ic, _env); \
+    GUTHTHILA_NEXT_CHAR(m, reader_type, _env, ic); \
+    GUTHTHILA_SKIP_SPACES(m, ic, reader_type, _env); \
     }
 #endif  
 
@@ -664,6 +697,7 @@
     int c = -1;
     guththila_attr_t * attr = NULL;
     int size = 0, i = 0, nmsp_counter, loop = 0, white_space = 0;
+    int reader_type = m->reader->type;
     /* Need to release the resources for attributes */
     size = GUTHTHILA_STACK_SIZE(m->attrib);
     for(i = 0; i < size; i++)
@@ -719,13 +753,13 @@
     do
     {
         loop = 0;
-        c = guththila_next_char(m, 0, env);
+        GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
         if(m->status == S_1)
         {
             while(isspace(c))
             {
-                c = guththila_next_char(m, 0, env);
-                if(c == -1)
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
+                if(c < 0)
                     return -1;
             }
             if('<' == c)
@@ -739,27 +773,27 @@
         }
         if('<' == c && m->status == S_2)
         {
-            c = guththila_next_char(m, 0, env);
+            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
             if(c != '?' && c != '!' && c != '/')
             {
                 /* We are at the beginig of a xml element */
                 if(GUTHTHILA_IS_VALID_STARTING_CHAR(c))
                 {
                     GUTHTHILA_TOKEN_OPEN(m, tok, env);
-                    c = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                     while(!GUTHTHILA_IS_SPACE(c) && c != '>' && c != '/')
                     {
-                        if(c == -1)
+                        if(c < 0)
                             return -1;
                         if(c != ':')
                         {
-                            c = guththila_next_char(m, 0, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                         }
                         else
                         {
                             /* We know for sure that this is a prefix */
                             guththila_token_close(m, tok, _prefix, 0, env);
-                            c = guththila_next_char(m, 0, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
                         }
                     }
@@ -774,14 +808,14 @@
                     guththila_stack_push(&m->elem, elem, env);
 #endif  
                 }
-                GUTHTHILA_SKIP_SPACES(m, c, env);
+                GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
                 /* Process the attributes */
                 for(;;)
                 {
                     /* Empty element */
                     if(c == '/')
                     {
-                        c = guththila_next_char(m, 0, env);
+                        GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                         if(c == '>')
                         {
                             m->guththila_event = GUTHTHILA_EMPTY_ELEMENT;
@@ -812,20 +846,20 @@
                         {
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
 
-                            c = guththila_next_char(m, 0, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                             while(!GUTHTHILA_IS_SPACE(c) && c != '=')
                             {
-                                if(c == -1)
+                                if(c < 0)
                                     return -1;
                                 if(c != ':')
                                 {
-                                    c = guththila_next_char(m, 0, env);
+                                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                                 }
                                 else if(c == ':')
                                 {
                                     /* Prefix */
                                     guththila_token_close(m, tok, _prefix, 0, env);
-                                    c = guththila_next_char(m, 0, env);
+                                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                                     GUTHTHILA_TOKEN_OPEN(m, tok, env);
                                 }
                             }
@@ -837,20 +871,20 @@
                             return -1;
                         }
                         /* Attribute Value */
-                        GUTHTHILA_PROCESS_EQU(m, c, quote, env);
+                        GUTHTHILA_PROCESS_EQU(m, c, quote, reader_type, env);
                         if('\'' == quote || '\"' == quote)
                         {
-                            c = guththila_next_char(m, 0, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
                             while(c != quote)
                             {
-                                if(c == -1)
+                                if(c < 0)
                                     return -1;
-                                c = guththila_next_char(m, 0, env);
+                                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                             }
                             guththila_token_close(m, tok, _attribute_value, 0, env);
-                            c = guththila_next_char(m, 0, env);
-                            GUTHTHILA_SKIP_SPACES(m, c, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
+                            GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
                         }
                         else
                         {
@@ -867,24 +901,24 @@
             {
                 /* End Element */
                 m->guththila_event = GUTHTHILA_END_ELEMENT;
-                c = guththila_next_char(m, -1, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                 if(GUTHTHILA_IS_VALID_STARTING_CHAR(c))
                 {
                     GUTHTHILA_TOKEN_OPEN(m, tok, env);
-                    c = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                     while(!GUTHTHILA_IS_SPACE(c) && c != '>')
                     {
-                        if(c == -1)
+                        if(c < 0)
                             return -1;
                         if(c != ':')
                         {
-                            c = guththila_next_char(m, 0, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                         }
                         else
                         {
                             /* Prefix */
                             guththila_token_close(m, tok, _prefix, 0, env);
-                            c = guththila_next_char(m, 0, env);
+                            GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                             GUTHTHILA_TOKEN_OPEN(m, tok, env);
                         }
                     }
@@ -927,7 +961,7 @@
                         guththila_tok_list_release_token(&m->tokens, elem->prefix,
env);
                     AXIS2_FREE(env->allocator, elem);
 #endif  
-                    GUTHTHILA_SKIP_SPACES(m, c, env);
+                    GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
                     if(c != '>')
                         return -1;
                     return GUTHTHILA_END_ELEMENT;
@@ -941,11 +975,11 @@
                     == c_arra[1])
                 {
                     int loop_state = 1;
-                    c = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                     GUTHTHILA_TOKEN_OPEN(m, tok, env);
                     while(loop_state)
                     {
-                        c = guththila_next_char(m, 0, env);
+                        GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                         if('-' == c)
                         {
                             if(2 == guththila_next_no_char(m, 0, c_arra, 2, env) &&
'-'
@@ -970,12 +1004,12 @@
                 }
                 else
                 {
-                    c = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                     while('<' != c)
                     {
-                        if(c == -1)
+                        if(c < 0)
                             return -1;
-                        c = guththila_next_char(m, -1, env);
+                        GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                     }
                 }
             }
@@ -1001,10 +1035,10 @@
 
             do
             {
-                c = guththila_next_char(m, -1, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                 if(!GUTHTHILA_IS_SPACE(c) && c != '<')
                     white_space = 0;
-                if(c == -1)
+                if(c < 0)
                     return -1;
             }
             while(c != '<');
@@ -1049,11 +1083,12 @@
     int c = -1;
     int quote = -1;
     int nc = -1;
+    int reader_type = m->reader->type;
     if(3 == guththila_next_no_char(m, GUTHTHILA_EOF, c_arra, 3, env) && 'x' == c_arra[0]
&& 'm'
         == c_arra[1] && 'l' == c_arra[2])
     {
-        c = guththila_next_char(m, GUTHTHILA_EOF, env);
-        GUTHTHILA_SKIP_SPACES(m, c, env);
+        GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
+        GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
         if(c == 'v')
         {
             GUTHTHILA_TOKEN_OPEN(m, tok, env);
@@ -1061,20 +1096,20 @@
                 == c_arra[1] && 's' == c_arra[2] && 'i' == c_arra[3] &&
'o' == c_arra[4] && 'n'
                 == c_arra[5])
             {
-                c = guththila_next_char(m, 0, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                 guththila_token_close(m, tok, _attribute_name, 0, env);
-                GUTHTHILA_PROCESS_EQU(m, c, quote, env);
-                nc = guththila_next_char(m, 0, env);
+                GUTHTHILA_PROCESS_EQU(m, c, quote, reader_type, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, nc);
                 GUTHTHILA_TOKEN_OPEN(m, tok, env);
                 while(nc != quote)
                 {
-                    if(nc == -1)
+                    if(nc < 0)
                         return -1;
-                    nc = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, nc);
                 }
                 guththila_token_close(m, tok, _attribute_value, 0, env);
-                c = guththila_next_char(m, 0, env);
-                GUTHTHILA_SKIP_SPACES(m, c, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
+                GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
             }
             else
             {
@@ -1088,20 +1123,20 @@
                 == c_arra[1] && 'o' == c_arra[2] && 'd' == c_arra[3] &&
'i' == c_arra[4] && 'n'
                 == c_arra[5] && 'g' == c_arra[6])
             {
-                c = guththila_next_char(m, 0, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                 guththila_token_close(m, tok, _attribute_name, 0, env);
-                GUTHTHILA_PROCESS_EQU(m, c, quote, env);
-                nc = guththila_next_char(m, 0, env);
+                GUTHTHILA_PROCESS_EQU(m, c, quote, reader_type, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, nc);
                 GUTHTHILA_TOKEN_OPEN(m, tok, env);
                 while(nc != quote)
                 {
-                    if(nc == -1)
+                    if(nc < 0)
                         return -1;
-                    nc = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                 }
                 guththila_token_close(m, tok, _attribute_value, 0, env);
-                c = guththila_next_char(m, 0, env);
-                GUTHTHILA_SKIP_SPACES(m, c, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
+                GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
             }
         }
         if(c == 's')
@@ -1111,25 +1146,27 @@
                 == c_arra[1] && 'n' == c_arra[2] && 'd' == c_arra[3] &&
'a' == c_arra[4] && 'l'
                 == c_arra[5] && 'o' == c_arra[6] && 'n' == c_arra[7] &&
'e' == c_arra[8])
             {
-                c = guththila_next_char(m, 0, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
                 guththila_token_close(m, tok, _attribute_name, 0, env);
-                GUTHTHILA_PROCESS_EQU(m, c, quote, env);
-                nc = guththila_next_char(m, 0, env);
+                GUTHTHILA_PROCESS_EQU(m, c, quote, reader_type, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, nc);
                 GUTHTHILA_TOKEN_OPEN(m, tok, env);
                 while(nc != quote)
                 {
-                    if(nc == -1)
+                    if(nc < 0)
                         return -1;
-                    nc = guththila_next_char(m, 0, env);
+                    GUTHTHILA_NEXT_CHAR(m, reader_type, env, nc);
                 }
                 guththila_token_close(m, tok, _attribute_value, 0, env);
-                c = guththila_next_char(m, 0, env);
-                GUTHTHILA_SKIP_SPACES(m, c, env);
+                GUTHTHILA_NEXT_CHAR(m, reader_type, env, c);
+                GUTHTHILA_SKIP_SPACES(m, c, reader_type, env);
             }
         }
         if(c == '?')
         {
-            if('>' == guththila_next_char(m, 0, env))
+            int nc;
+            GUTHTHILA_NEXT_CHAR(m, reader_type, env, nc);
+            if('>' == nc)
             {
                 m->guththila_event = GUTHTHILA_START_DOCUMENT;
             }
@@ -1477,7 +1514,6 @@
 static int
 guththila_next_char(
     guththila_t * m,
-    int eof,
     const axutil_env_t * env)
 {
     int c;
@@ -1485,16 +1521,19 @@
     int temp;
     guththila_char_t **temp1;
     size_t * temp2, *temp3;
+
     /* we have a buffered reader. Easiest case just fetch the character from 
      * the buffer. Here we have a single buffer. 
      * */
-    if(m->reader->type == GUTHTHILA_MEMORY_READER && m->next < GUTHTHILA_BUFFER_CURRENT_DATA_SIZE(
-        m->buffer))
+    if(m->reader->type == GUTHTHILA_MEMORY_READER)
     {
-        c = m->buffer.buff[0][m->next++];
-        return c >= 0 ? c : -1;
+        int index = m->next++;
+        if(index < m->buffer.data_size[0])
+        {
+            return m->buffer.buff[0][index];
+        }
     }
-    else if(m->reader->type == GUTHTHILA_IO_READER || m->reader->type == GUTHTHILA_FILE_READER)
+    else
     {
         /* comlex stuff. We have a array of buffers */
         if(m->buffer.cur_buff != -1 && m->next < GUTHTHILA_BUFFER_PRE_DATA_SIZE(m->buffer)
@@ -1503,7 +1542,7 @@
             /* What we are looking for is already in the buffer */
             c = m->buffer.buff[m->buffer.cur_buff][m->next++ - GUTHTHILA_BUFFER_PRE_DATA_SIZE(
                 m->buffer)];
-            return c >= 0 ? c : -1;
+            return c;
         }
         else if(m->buffer.cur_buff != -1 && m->next >= GUTHTHILA_BUFFER_PRE_DATA_SIZE(m->buffer)
             + GUTHTHILA_BUFFER_CURRENT_DATA_SIZE(m->buffer))
@@ -1567,7 +1606,7 @@
             }
             c = m->buffer.buff[m->buffer.cur_buff][m->next++ - GUTHTHILA_BUFFER_PRE_DATA_SIZE(
                 m->buffer)];
-            return c >= 0 ? c : -1;
+            return c;
         }
         /* Initial stage. We dont' have the array of buffers allocated*/
         else if(m->buffer.cur_buff == -1)
@@ -1580,7 +1619,7 @@
                 GUTHTHILA_BUFFER_DEF_SIZE, env);
             m->buffer.data_size[0] = temp;
             c = m->buffer.buff[0][m->next++];
-            return c >= 0 ? c : -1;
+            return c;
         }
     }
     return -1;



Mime
View raw message