You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2008/04/22 16:23:17 UTC

svn commit: r650528 - in /xerces/c/trunk/src/xercesc: framework/XMLBuffer.hpp internal/XMLReader.cpp internal/XMLReader.hpp internal/XMLScanner.cpp util/XMLString.hpp

Author: amassari
Date: Tue Apr 22 07:22:53 2008
New Revision: 650528

URL: http://svn.apache.org/viewvc?rev=650528&view=rev
Log:
Performance improvements

Modified:
    xerces/c/trunk/src/xercesc/framework/XMLBuffer.hpp
    xerces/c/trunk/src/xercesc/internal/XMLReader.cpp
    xerces/c/trunk/src/xercesc/internal/XMLReader.hpp
    xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp
    xerces/c/trunk/src/xercesc/util/XMLString.hpp

Modified: xerces/c/trunk/src/xercesc/framework/XMLBuffer.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/framework/XMLBuffer.hpp?rev=650528&r1=650527&r2=650528&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/XMLBuffer.hpp (original)
+++ xerces/c/trunk/src/xercesc/framework/XMLBuffer.hpp Tue Apr 22 07:22:53 2008
@@ -155,7 +155,8 @@
     void set (const XMLCh* const chars)
     {
         fIndex = 0;
-        append(chars);
+        if (chars != 0 && *chars != 0)
+            append(chars);
     }
 
     const XMLCh* getRawBuffer() const
@@ -173,7 +174,6 @@
     void reset()
     {
         fIndex = 0;
-        fBuffer[0] = 0;
     }
 
     // -----------------------------------------------------------------------

Modified: xerces/c/trunk/src/xercesc/internal/XMLReader.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/XMLReader.cpp?rev=650528&r1=650527&r2=650528&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLReader.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLReader.cpp Tue Apr 22 07:22:53 2008
@@ -768,9 +768,8 @@
                 continue;
             }
 
-            if (!isNCNameChar(fCharBuf[fCharIndex])) {
+            if ((fgCharCharsTable[fCharBuf[fCharIndex]] & gNCNameCharMask) == 0)
                 break;
-            }
 
             fCharIndex++;
         }
@@ -1798,8 +1797,9 @@
     // 1. the two-character sequence #xD #xA
     // 2. the two-character sequence #xD #x85
     // 5. any #xD character that is not immediately followed by #xA or #x85.
-    if (curCh == chCR)
+    switch(curCh)
     {
+    case chCR:
         fCurCol = 1;
         fCurLine++;
 
@@ -1819,16 +1819,17 @@
             }
             curCh = chLF;
         }
-    }
-    else if (curCh == chLF)                   
-    {
+        break;
+
+    case chLF:
         fCurCol = 1;
         fCurLine++;
-    }
+        break;
+
     // 3. the single character #x85
     // 4. the single character #x2028
-    else if (curCh == chNEL || curCh == chLineSeparator)
-    {
+    case chNEL:
+    case chLineSeparator:
         if (inDecl && fXMLVersion == XMLV1_1)
         {
 
@@ -1858,9 +1859,8 @@
             fCurLine++;
             curCh = chLF;
         }
-    }
-    else
-    {
+        break;
+    default:
         fCurCol++;
     }
 }

Modified: xerces/c/trunk/src/xercesc/internal/XMLReader.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/XMLReader.hpp?rev=650528&r1=650527&r2=650528&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLReader.hpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLReader.hpp Tue Apr 22 07:22:53 2008
@@ -624,16 +624,16 @@
 // ---------------------------------------------------------------------------
 inline void XMLReader::movePlainContentChars(XMLBuffer &dest)
 {
-    const XMLCh* cursor = &fCharBuf[fCharIndex], *start = cursor, *end = &fCharBuf[fCharsAvail];
+    const XMLSize_t chunkSize = fCharsAvail - fCharIndex;
+    const XMLCh* cursor = &fCharBuf[fCharIndex];
+    XMLSize_t count=0;
+    for(;count<chunkSize && (fgCharCharsTable[*cursor++] & gPlainContentCharMask) != 0;++count);    // yes, it's an empty loop
 
-    while (cursor < end && isPlainContentChar(*cursor))
-        cursor++;
-
-    if (cursor != start)
+    if (count!=0)
     {
-        fCharIndex  = cursor - fCharBuf;
-        fCurCol    += (unsigned long)(cursor - start);
-        dest.append(start, cursor - start);
+        dest.append(&fCharBuf[fCharIndex], count);
+        fCharIndex += count;
+        fCurCol    += (unsigned long)count;
     }
 }
 

Modified: xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp?rev=650528&r1=650527&r2=650528&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp Tue Apr 22 07:22:53 2008
@@ -1876,19 +1876,13 @@
         nextCh = fReaderMgr.peekNextChar();
     }
 
-    //  Check for special chars. Start with the most
-    //  obvious end of file, which should be legal here at top level.
-    if (!nextCh)
-        return Token_EOF;
-
-
-    //  If it's not a '<' we must be in content.
+    //  If it's not a '<' we must be in content (unless it's a EOF)
     //
     //  This includes entity references '&' of some sort. These must
     //  be character data because that's the only place a reference can
     //  occur in content.
     if (nextCh != chOpenAngle)
-        return Token_CharData;
+        return nextCh?Token_CharData:Token_EOF;
 
     //  Ok it had to have been a '<' character. So get it out of the reader
     //  and store the reader number where we saw it, passing it back to the
@@ -1898,42 +1892,42 @@
 
     //  Ok, so lets go through the things that it could be at this point which
     //  are all some form of markup.
-    nextCh = fReaderMgr.peekNextChar();
-
-    if (nextCh == chForwardSlash)
+    switch(fReaderMgr.peekNextChar())
     {
-        fReaderMgr.getNextChar();
-        return Token_EndTag;
-    }
-    else if (nextCh == chBang)
-    {
-        static const XMLCh gCDATAStr[] =
+    case chForwardSlash:
         {
-                chBang, chOpenSquare, chLatin_C, chLatin_D, chLatin_A
-            ,   chLatin_T, chLatin_A, chNull
-        };
-
-        static const XMLCh gCommentString[] =
+            fReaderMgr.getNextChar();
+            return Token_EndTag;
+        }
+    case chBang:
         {
-            chBang, chDash, chDash, chNull
-        };
-
-        if (fReaderMgr.skippedString(gCDATAStr))
-            return Token_CData;
-
-        if (fReaderMgr.skippedString(gCommentString))
-            return Token_Comment;
-
-        emitError(XMLErrs::ExpectedCommentOrCDATA);
-        return Token_Unknown;
-    }
-    else if (nextCh == chQuestion)
-    {
-        // It must be a PI
-        fReaderMgr.getNextChar();
-        return Token_PI;
+            static const XMLCh gCDATAStr[] =
+            {
+                    chBang, chOpenSquare, chLatin_C, chLatin_D, chLatin_A
+                ,   chLatin_T, chLatin_A, chNull
+            };
+
+            static const XMLCh gCommentString[] =
+            {
+                chBang, chDash, chDash, chNull
+            };
+
+            if (fReaderMgr.skippedString(gCDATAStr))
+                return Token_CData;
+
+            if (fReaderMgr.skippedString(gCommentString))
+                return Token_Comment;
+
+            emitError(XMLErrs::ExpectedCommentOrCDATA);
+            return Token_Unknown;
+        }
+    case chQuestion:
+        {
+            // It must be a PI
+            fReaderMgr.getNextChar();
+            return Token_PI;
+        }
     }
-
     //  Assume its an element name, so return with a start tag token. If it
     //  turns out not to be, then it will fail when it cannot get a valid tag.
     return Token_StartTag;

Modified: xerces/c/trunk/src/xercesc/util/XMLString.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLString.hpp?rev=650528&r1=650527&r2=650528&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLString.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLString.hpp Tue Apr 22 07:22:53 2008
@@ -1451,53 +1451,35 @@
 inline bool XMLString::equals(   const XMLCh* str1
                                , const XMLCh* str2)
 {
-    if(str1==str2)
+    if (str1 == str2)
         return true;
 
-    if (str1 == 0 || str2 == 0) {
-        if ((str1 != 0 && *str1) || (str2 != 0 && *str2))
+    if (str1 == 0 || str2 == 0)
+        return ((!str1 || !*str1) && (!str2 || !*str2));
+    
+    while (*str1)
+        if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
             return false;
-        else
-            return true;
-    }
-
-    while (*str1 == *str2)
-    {
-        // If either has ended, then they both ended, so equal
-        if (!*str1)
-            return true;
-
-        // Move upwards for the next round
-        str1++;
-        str2++;
-    }
-    return false;
+
+    // either both ended (and *str2 is 0 too), or str2 is longer
+    return (*str2==0);
 }
 
 inline bool XMLString::equals(   const char* str1
                                , const char* str2)
 {
-    if(str1==str2)
+    if (str1 == str2)
         return true;
 
-    if (str1 == 0 || str2 == 0) {
-        if ((str1 != 0 && *str1) || (str2 != 0 && *str2))
+    if (str1 == 0 || str2 == 0)
+        return ((!str1 || !*str1) && (!str2 || !*str2));
+
+    while (*str1)
+        if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
             return false;
-        else
-            return true;
-    }
-
-    while (*str1 == *str2)
-    {
-        // If either has ended, then they both ended, so equal
-        if (!*str1)
-            return true;
-
-        // Move upwards for the next round
-        str1++;
-        str2++;
-    }
-    return false;
+
+    // either both ended (and *str2 is 0 too), or str2 is longer
+    return (*str2==0);
 }
 
 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org