Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3912

Show
Ignore:
Timestamp:
08/25/08 22:36:45 (3 months ago)
Author:
kris
Message:

made parser a bit faster

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/text/json/JsonParser.d

    r3909 r3912  
    171171                    ++p; 
    172172                 
    173                 while (p < e && *p <= 32) 
     173                while (*p <= 32)  
    174174                       ++p; 
    175175 
     
    234234 
    235235                       case 'f': 
    236                             return match ("false", Token.False); 
     236                            return match ("false", Token.False);  
    237237 
    238238                       default: 
     
    241241 
    242242                return parseNumber; 
    243         } 
    244          
    245         /*********************************************************************** 
    246          
    247         ***********************************************************************/ 
    248          
    249         private bool parseNumber () 
    250         { 
    251                 auto p = str.ptr; 
    252                 auto e = str.end; 
    253  
    254                 curLoc = p; 
    255                 curType = Token.Number; 
    256  
    257                 while (p < e) 
    258                       { 
    259                       auto c = *p; 
    260                       if ((c >= '0' && c <= '9') || c is '.' || c is 'e')  
    261                            ++p; 
    262                       else 
    263                          break; 
    264                       }                  
    265  
    266                 if (p < e)  
    267                     curLen = p - curLoc; 
    268                 else 
    269                    unexpectedEOF ("after number"); 
    270  
    271                 str.ptr = p; 
    272                 return true; 
    273243        } 
    274244         
     
    295265 
    296266                str.ptr = p + 1; 
     267                return true; 
     268        } 
     269         
     270        /*********************************************************************** 
     271         
     272        ***********************************************************************/ 
     273         
     274        private bool parseNumber () 
     275        { 
     276                auto p = str.ptr; 
     277                auto e = str.end; 
     278                auto c = *(curLoc = p); 
     279 
     280                curType = Token.Number; 
     281 
     282                while (c >= '0' && c <= '9') c = *++p;                  
     283 
     284                if (c is '.') 
     285                    while (c = *++p, c >= '0' && c <= '9') {}                  
     286 
     287                if (c is 'e') 
     288                    while (c = *++p, c >= '0' && c <= '9') {} 
     289 
     290                if (p < e)  
     291                    curLen = p - curLoc; 
     292                else 
     293                   unexpectedEOF ("after number"); 
     294 
     295                str.ptr = p; 
    297296                return true; 
    298297        }