From: Aaron Kennedy Date: Fri, 22 Jul 2011 06:18:06 +0000 (+1000) Subject: Special case integers and strings in lexer X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b048a40d7aab29b44d9c548292ab4b307d8d40c0;p=konrad%2Fqtdeclarative.git Special case integers and strings in lexer 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 --- diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index 6c6338b..e904ff6 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -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 chars; chars.append(ch.unicode());