Special case integers and strings in lexer
authorAaron Kennedy <aaron.kennedy@nokia.com>
Fri, 22 Jul 2011 06:18:06 +0000 (16:18 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 30 Aug 2011 11:18:28 +0000 (13:18 +0200)
Reduces the amount of copying for integer numbers and uses a raw
QStringRef for unescaped strings.

Change-Id: I2ad29f4c67be72495e3209081761b9a1bb503f26
Reviewed-on: http://codereview.qt.nokia.com/3773
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>

src/declarative/qml/parser/qdeclarativejslexer.cpp

index 6c6338b..e904ff6 100644 (file)
@@ -530,11 +530,29 @@ again:
     case '\'':
     case '"': {
         const QChar quote = ch;
-        _tokenText.resize(0);
         _validTokenText = true;
 
         bool multilineStringLiteral = false;
 
+        const QChar *startCode = _codePtr;
+
+        while (!_char.isNull()) {
+            if (_char == QLatin1Char('\n') || _char == QLatin1Char('\\')) {
+                break;
+            } else if (_char == quote) {
+                _tokenSpell = _engine->midRef(startCode - _code.unicode() - 1, _codePtr - startCode);
+                scanChar();
+
+                return T_STRING_LITERAL;
+            }
+            scanChar();
+        }
+
+        _tokenText.resize(0);
+        startCode--;
+        while (startCode != _codePtr - 1) 
+            _tokenText += *startCode++;
+
         while (! _char.isNull()) {
             if (_char == QLatin1Char('\n')) {
                 multilineStringLiteral = true;
@@ -692,6 +710,24 @@ again:
                 }
             }
         } else if (QDeclarativeUtils::isDigit(ch)) {
+            if (ch != '0') {
+                int integer = ch.unicode() - '0';
+
+                QChar n = _char;
+                const QChar *code = _codePtr;
+                while (QDeclarativeUtils::isDigit(n)) {
+                    integer = integer * 10 + (n.unicode() - '0');
+                    n = *code++;
+                }
+
+                if (n != QLatin1Char('.') && n != QLatin1Char('e') && n != QLatin1Char('E')) {
+                    _codePtr = code - 1;
+                    scanChar();
+                    _tokenValue = integer;
+                    return T_NUMERIC_LITERAL;
+                } 
+            }
+
             QVarLengthArray<char,32> chars;
             chars.append(ch.unicode());