Title: [133668] trunk/Source/_javascript_Core
Revision
133668
Author
[email protected]
Date
2012-11-06 14:01:51 -0800 (Tue, 06 Nov 2012)

Log Message

Lexer::scanRegExp, create 8 bit pattern and flag Identifiers from 16 bit source when possible
https://bugs.webkit.org/show_bug.cgi?id=101013

Reviewed by Darin Adler.

Changed scanRegExp so that it will create 8 bit identifiers from 8 bit sources and from 16 bit sources
whan all the characters are 8 bit.  Using two templated helpers, the "is all 8 bit" check is only performed
on 16 bit sources.  The first helper is orCharacter() that will accumulate the or value of all characters
only for 16 bit sources.  Replaced the helper Lexer::makeIdentifierSameType() with Lexer::makeRightSizedIdentifier().

* parser/Lexer.cpp:
(JSC::orCharacter<LChar>): Explicit template that serves as a placeholder.
(JSC::orCharacter<UChar>): Explicit template that actually or accumulates characters.
(JSC::Lexer::scanRegExp):
* parser/Lexer.h:
(Lexer):
(JSC::Lexer::makeRightSizedIdentifier<LChar>): New template that always creates an 8 bit Identifier.
(JSC::Lexer::makeRightSizedIdentifier<UChar>): New template that creates an 8 bit Identifier for 8 bit
data in a 16 bit source.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (133667 => 133668)


--- trunk/Source/_javascript_Core/ChangeLog	2012-11-06 22:00:23 UTC (rev 133667)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-11-06 22:01:51 UTC (rev 133668)
@@ -1,3 +1,25 @@
+2012-11-06  Michael Saboff  <[email protected]>
+
+        Lexer::scanRegExp, create 8 bit pattern and flag Identifiers from 16 bit source when possible
+        https://bugs.webkit.org/show_bug.cgi?id=101013
+
+        Reviewed by Darin Adler.
+
+        Changed scanRegExp so that it will create 8 bit identifiers from 8 bit sources and from 16 bit sources
+        whan all the characters are 8 bit.  Using two templated helpers, the "is all 8 bit" check is only performed
+        on 16 bit sources.  The first helper is orCharacter() that will accumulate the or value of all characters
+        only for 16 bit sources.  Replaced the helper Lexer::makeIdentifierSameType() with Lexer::makeRightSizedIdentifier().
+
+        * parser/Lexer.cpp:
+        (JSC::orCharacter<LChar>): Explicit template that serves as a placeholder.
+        (JSC::orCharacter<UChar>): Explicit template that actually or accumulates characters.
+        (JSC::Lexer::scanRegExp):
+        * parser/Lexer.h:
+        (Lexer):
+        (JSC::Lexer::makeRightSizedIdentifier<LChar>): New template that always creates an 8 bit Identifier.
+        (JSC::Lexer::makeRightSizedIdentifier<UChar>): New template that creates an 8 bit Identifier for 8 bit
+        data in a 16 bit source.
+
 2012-11-06  Filip Pizlo  <[email protected]>
 
         Indentation of JSCell.h is wrong

Modified: trunk/Source/_javascript_Core/parser/Lexer.cpp (133667 => 133668)


--- trunk/Source/_javascript_Core/parser/Lexer.cpp	2012-11-06 22:00:23 UTC (rev 133667)
+++ trunk/Source/_javascript_Core/parser/Lexer.cpp	2012-11-06 22:01:51 UTC (rev 133668)
@@ -1686,12 +1686,25 @@
 }
 
 template <typename T>
+static inline void orCharacter(UChar&, UChar);
+
+template <>
+inline void orCharacter<LChar>(UChar&, UChar) { }
+
+template <>
+inline void orCharacter<UChar>(UChar& orAccumulator, UChar character)
+{
+    orAccumulator |= character;
+}
+
+template <typename T>
 bool Lexer<T>::scanRegExp(const Identifier*& pattern, const Identifier*& flags, UChar patternPrefix)
 {
     ASSERT(m_buffer16.isEmpty());
 
     bool lastWasEscape = false;
     bool inBrackets = false;
+    UChar charactersOredTogether = 0;
 
     if (patternPrefix) {
         ASSERT(!isLineTerminator(patternPrefix));
@@ -1714,6 +1727,7 @@
             break;
 
         record16(prev);
+        orCharacter<T>(charactersOredTogether, prev);
 
         if (lastWasEscape) {
             lastWasEscape = false;
@@ -1733,15 +1747,18 @@
         }
     }
 
-    pattern = makeIdentifierSameType(m_buffer16.data(), m_buffer16.size());
+    pattern = makeRightSizedIdentifier(m_buffer16.data(), m_buffer16.size(), charactersOredTogether);
+
     m_buffer16.resize(0);
+    charactersOredTogether = 0;
 
     while (isIdentPart(m_current)) {
         record16(m_current);
+        orCharacter<T>(charactersOredTogether, m_current);
         shift();
     }
 
-    flags = makeIdentifierSameType(m_buffer16.data(), m_buffer16.size());
+    flags = makeRightSizedIdentifier(m_buffer16.data(), m_buffer16.size(), charactersOredTogether);
     m_buffer16.resize(0);
 
     return true;

Modified: trunk/Source/_javascript_Core/parser/Lexer.h (133667 => 133668)


--- trunk/Source/_javascript_Core/parser/Lexer.h	2012-11-06 22:00:23 UTC (rev 133667)
+++ trunk/Source/_javascript_Core/parser/Lexer.h	2012-11-06 22:01:51 UTC (rev 133668)
@@ -148,7 +148,7 @@
     ALWAYS_INLINE const Identifier* makeIdentifier(const UChar* characters, size_t length);
     ALWAYS_INLINE const Identifier* makeLCharIdentifier(const LChar* characters, size_t length);
     ALWAYS_INLINE const Identifier* makeLCharIdentifier(const UChar* characters, size_t length);
-    ALWAYS_INLINE const Identifier* makeIdentifierSameType(const UChar* characters, size_t length);
+    ALWAYS_INLINE const Identifier* makeRightSizedIdentifier(const UChar* characters, size_t length, UChar orAllChars);
     ALWAYS_INLINE const Identifier* makeIdentifierLCharFromUChar(const UChar* characters, size_t length);
 
     ALWAYS_INLINE bool lastTokenWasRestrKeyword() const;
@@ -242,14 +242,17 @@
 }
 
 template <>
-ALWAYS_INLINE const Identifier* Lexer<LChar>::makeIdentifierSameType(const UChar* characters, size_t length)
+ALWAYS_INLINE const Identifier* Lexer<LChar>::makeRightSizedIdentifier(const UChar* characters, size_t length, UChar)
 {
     return &m_arena->makeIdentifierLCharFromUChar(m_globalData, characters, length);
 }
 
 template <>
-ALWAYS_INLINE const Identifier* Lexer<UChar>::makeIdentifierSameType(const UChar* characters, size_t length)
+ALWAYS_INLINE const Identifier* Lexer<UChar>::makeRightSizedIdentifier(const UChar* characters, size_t length, UChar orAllChars)
 {
+    if (!(orAllChars & ~0xff))
+        return &m_arena->makeIdentifierLCharFromUChar(m_globalData, characters, length);
+
     return &m_arena->makeIdentifier(m_globalData, characters, length);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to