[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

zherczeg at webkit.org zherczeg at webkit.org
Wed Dec 22 11:46:19 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 8b3c06dd7b979091fd3b7447d457a3aa6be6b135
Author: zherczeg at webkit.org <zherczeg at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Aug 6 10:33:10 2010 +0000

    Refactor identifier parsing in lexer
    https://bugs.webkit.org/show_bug.cgi?id=41845
    
    Reviewed by Darin Adler.
    
    The code is refactored to avoid gotos. The new code
    has the same performance as the old one.
    
    SunSpider --parse-only: no change (from 34.0ms to 33.6ms)
    SunSpider: no change (from 523.2ms to 523.5ms)
    
    * parser/Lexer.cpp:
    (JSC::Lexer::parseIdent):
    (JSC::Lexer::lex):
    * parser/Lexer.h:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64827 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 70b8b3f..2dff0ad 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,21 @@
+2010-08-06  Zoltan Herczeg  <zherczeg at webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Refactor identifier parsing in lexer
+        https://bugs.webkit.org/show_bug.cgi?id=41845
+
+        The code is refactored to avoid gotos. The new code
+        has the same performance as the old one.
+
+        SunSpider --parse-only: no change (from 34.0ms to 33.6ms)
+        SunSpider: no change (from 523.2ms to 523.5ms)
+
+        * parser/Lexer.cpp:
+        (JSC::Lexer::parseIdent):
+        (JSC::Lexer::lex):
+        * parser/Lexer.h:
+
 2010-08-06  Gabor Loki  <loki at webkit.org>
 
         Reviewed by Gavin Barraclough.
diff --git a/JavaScriptCore/parser/Lexer.cpp b/JavaScriptCore/parser/Lexer.cpp
index d7a122e..877e89a 100644
--- a/JavaScriptCore/parser/Lexer.cpp
+++ b/JavaScriptCore/parser/Lexer.cpp
@@ -399,6 +399,60 @@ inline void Lexer::record16(int c)
     record16(UChar(static_cast<unsigned short>(c)));
 }
 
+ALWAYS_INLINE JSTokenType Lexer::parseIdentifier(JSTokenData* lvalp, LexType lexType)
+{
+    bool bufferRequired = false;
+    const UChar* identifierStart = currentCharacter();
+    int identifierLength;
+
+    while (true) {
+        if (LIKELY(isIdentPart(m_current))) {
+            shift();
+            continue;
+        }
+        if (LIKELY(m_current != '\\'))
+            break;
+
+        // \uXXXX unicode characters.
+        bufferRequired = true;
+        if (identifierStart != currentCharacter())
+            m_buffer16.append(identifierStart, currentCharacter() - identifierStart);
+        shift();
+        if (UNLIKELY(m_current != 'u'))
+            return ERRORTOK;
+        shift();
+        int character = getUnicodeCharacter();
+        if (UNLIKELY(character == -1))
+            return ERRORTOK;
+        if (UNLIKELY(m_buffer16.size() ? !isIdentPart(character) : !isIdentStart(character)))
+            return ERRORTOK;
+        record16(character);
+        identifierStart = currentCharacter();
+    }
+
+    if (!bufferRequired)
+        identifierLength = currentCharacter() - identifierStart;
+    else {
+        if (identifierStart != currentCharacter())
+            m_buffer16.append(identifierStart, currentCharacter() - identifierStart);
+        identifierStart = m_buffer16.data();
+        identifierLength = m_buffer16.size();
+    }
+
+    const Identifier* ident = makeIdentifier(identifierStart, identifierLength);
+    lvalp->ident = ident;
+    m_delimited = false;
+
+    if (LIKELY(!bufferRequired && lexType == IdentifyReservedWords)) {
+        // Keywords must not be recognized if there was an \uXXXX in the identifier.
+        const HashEntry* entry = m_keywordTable.entry(m_globalData, *ident);
+        return entry ? static_cast<JSTokenType>(entry->lexerValue()) : IDENT;
+    }
+
+    m_buffer16.resize(0);
+    return IDENT;
+}
+
 ALWAYS_INLINE bool Lexer::parseString(JSTokenData* lvalp)
 {
     int stringQuoteCharacter = m_current;
@@ -488,7 +542,6 @@ JSTokenType Lexer::lex(JSTokenData* lvalp, JSTokenInfo* llocp, LexType lexType)
     ASSERT(m_buffer16.isEmpty());
 
     JSTokenType token = ERRORTOK;
-    int identChar = 0;
     m_terminator = false;
 
 start:
@@ -753,8 +806,6 @@ start:
         shift();
         token = CLOSEBRACE;
         break;
-    case CharacterBackSlash:
-        goto startIdentifierWithBackslash;
     case CharacterZero:
         goto startNumberWithZeroDigit;
     case CharacterNumber:
@@ -768,7 +819,10 @@ start:
         break;
     case CharacterIdentifierStart:
         ASSERT(isIdentStart(m_current));
-        goto startIdentifierOrKeyword;
+        // Fall through into CharacterBackSlash.
+    case CharacterBackSlash:
+        token = parseIdentifier(lvalp, lexType);
+        break;
     case CharacterLineTerminator:
         ASSERT(isLineTerminator(m_current));
         shiftLineTerminator();
@@ -789,53 +843,6 @@ start:
     m_atLineStart = false;
     goto returnToken;
 
-startIdentifierWithBackslash: {
-    shift();
-    if (UNLIKELY(m_current != 'u'))
-        goto returnError;
-    shift();
-
-    identChar = getUnicodeCharacter();
-    if (UNLIKELY(identChar == -1))
-        goto returnError;
-    if (UNLIKELY(!isIdentStart(identChar)))
-        goto returnError;
-    goto inIdentifierAfterCharacterCheck;
-}
-
-startIdentifierOrKeyword: {
-    const UChar* identifierStart = currentCharacter();
-    shift();
-    while (isIdentPart(m_current))
-        shift();
-    if (LIKELY(m_current != '\\')) {
-        // Fast case for idents which does not contain \uCCCC characters
-        lvalp->ident = makeIdentifier(identifierStart, currentCharacter() - identifierStart);
-        goto doneIdentifierOrKeyword;
-    }
-    m_buffer16.append(identifierStart, currentCharacter() - identifierStart);
-}
-
-    do {
-        shift();
-        if (UNLIKELY(m_current != 'u'))
-            goto returnError;
-        shift();
-        identChar = getUnicodeCharacter();
-        if (UNLIKELY(identChar == -1))
-            goto returnError;
-        if (UNLIKELY(!isIdentPart(identChar)))
-            goto returnError;
-inIdentifierAfterCharacterCheck:
-        record16(identChar);
-
-        while (isIdentPart(m_current)) {
-            record16(m_current);
-            shift();
-        }
-    } while (UNLIKELY(m_current == '\\'));
-    goto doneIdentifier;
-
 inSingleLineComment:
     while (!isLineTerminator(m_current)) {
         if (UNLIKELY(m_current == -1))
@@ -1008,27 +1015,7 @@ doneNumeric:
 doneSemicolon:
     token = SEMICOLON;
     m_delimited = true;
-    goto returnToken;
-
-doneIdentifier:
-    m_atLineStart = false;
-    m_delimited = false;
-    lvalp->ident = makeIdentifier(m_buffer16.data(), m_buffer16.size());
-    m_buffer16.resize(0);
-    token = IDENT;
-    goto returnToken;
-
-doneIdentifierOrKeyword: {
-    m_atLineStart = false;
-    m_delimited = false;
-    m_buffer16.resize(0);
-    if (lexType == IdentifyReservedWords) {
-        const HashEntry* entry = m_keywordTable.entry(m_globalData, *lvalp->ident);
-        token = entry ? static_cast<JSTokenType>(entry->lexerValue()) : IDENT;
-    } else
-        token = IDENT;
     // Fall through into returnToken.
-}
 
 returnToken: {
     int lineNumber = m_lineNumber;
diff --git a/JavaScriptCore/parser/Lexer.h b/JavaScriptCore/parser/Lexer.h
index 4f7af44..3d97cc1 100644
--- a/JavaScriptCore/parser/Lexer.h
+++ b/JavaScriptCore/parser/Lexer.h
@@ -94,6 +94,7 @@ namespace JSC {
 
         ALWAYS_INLINE bool lastTokenWasRestrKeyword() const;
 
+        ALWAYS_INLINE JSTokenType parseIdentifier(JSTokenData*, LexType);
         ALWAYS_INLINE bool parseString(JSTokenData* lvalp);
 
         static const size_t initialReadBufferCapacity = 32;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list