Several structures and enums in the Yarr interpreter can be shrunk
authorrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 20:39:11 +0000 (20:39 +0000)
committerrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Apr 2019 20:39:11 +0000 (20:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196923

Reviewed by Saam Barati.

YarrOp: 88 -> 80
RegularExpression: 40 -> 32
ByteTerm: 56 -> 48
PatternTerm: 56 -> 48

* yarr/RegularExpression.cpp:
* yarr/YarrInterpreter.h:
* yarr/YarrJIT.cpp:
(JSC::Yarr::YarrGenerator::YarrOp::YarrOp):
* yarr/YarrParser.h:
* yarr/YarrPattern.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244286 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/yarr/RegularExpression.cpp
Source/JavaScriptCore/yarr/YarrInterpreter.h
Source/JavaScriptCore/yarr/YarrJIT.cpp
Source/JavaScriptCore/yarr/YarrParser.h
Source/JavaScriptCore/yarr/YarrPattern.h

index fdca786..77400bd 100644 (file)
@@ -1,3 +1,22 @@
+2019-04-15  Robin Morisset  <rmorisset@apple.com>
+
+        Several structures and enums in the Yarr interpreter can be shrunk
+        https://bugs.webkit.org/show_bug.cgi?id=196923
+
+        Reviewed by Saam Barati.
+
+        YarrOp: 88 -> 80
+        RegularExpression: 40 -> 32
+        ByteTerm: 56 -> 48
+        PatternTerm: 56 -> 48
+
+        * yarr/RegularExpression.cpp:
+        * yarr/YarrInterpreter.h:
+        * yarr/YarrJIT.cpp:
+        (JSC::Yarr::YarrGenerator::YarrOp::YarrOp):
+        * yarr/YarrParser.h:
+        * yarr/YarrPattern.h:
+
 2019-04-15  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: REGRESSION(r244172): crash when trying to add extra domain while inspecting JSContext
index f121579..4394ae5 100644 (file)
@@ -43,11 +43,6 @@ public:
         return adoptRef(*new Private(pattern, caseSensitivity, multilineMode, unicodeMode));
     }
 
-    int lastMatchLength { -1 };
-
-    unsigned m_numSubpatterns;
-    std::unique_ptr<JSC::Yarr::BytecodePattern> m_regExpByteCode;
-
 private:
     Private(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode, UnicodeMode unicodeMode)
         : m_regExpByteCode(compile(pattern, caseSensitivity, multilineMode, unicodeMode))
@@ -78,8 +73,13 @@ private:
         return JSC::Yarr::byteCompile(pattern, &m_regexAllocator);
     }
 
-    BumpPointerAllocator m_regexAllocator;
     JSC::Yarr::ErrorCode m_constructionErrorCode { Yarr::ErrorCode::NoError };
+    BumpPointerAllocator m_regexAllocator;
+
+public:
+    int lastMatchLength { -1 };
+    unsigned m_numSubpatterns;
+    std::unique_ptr<JSC::Yarr::BytecodePattern> m_regExpByteCode;
 };
 
 RegularExpression::RegularExpression(const String& pattern, TextCaseSensitivity caseSensitivity, MultilineMode multilineMode, UnicodeMode unicodeMode)
index 4b85bed..6ec290e 100644 (file)
@@ -39,7 +39,38 @@ namespace JSC { namespace Yarr {
 class ByteDisjunction;
 
 struct ByteTerm {
-    enum Type {
+    union {
+        struct {
+            union {
+                UChar32 patternCharacter;
+                struct {
+                    UChar32 lo;
+                    UChar32 hi;
+                } casedCharacter;
+                CharacterClass* characterClass;
+                unsigned subpatternId;
+            };
+            union {
+                ByteDisjunction* parenthesesDisjunction;
+                unsigned parenthesesWidth;
+            };
+            QuantifierType quantityType;
+            unsigned quantityMinCount;
+            unsigned quantityMaxCount;
+        } atom;
+        struct {
+            int next;
+            int end;
+            bool onceThrough;
+        } alternative;
+        struct {
+            bool m_bol : 1;
+            bool m_eol : 1;
+        } anchors;
+        unsigned checkInputCount;
+    };
+    unsigned frameLocation;
+    enum Type : uint8_t {
         TypeBodyAlternativeBegin,
         TypeBodyAlternativeDisjunction,
         TypeBodyAlternativeEnd,
@@ -72,37 +103,6 @@ struct ByteTerm {
         TypeUncheckInput,
         TypeDotStarEnclosure,
     } type;
-    union {
-        struct {
-            union {
-                UChar32 patternCharacter;
-                struct {
-                    UChar32 lo;
-                    UChar32 hi;
-                } casedCharacter;
-                CharacterClass* characterClass;
-                unsigned subpatternId;
-            };
-            union {
-                ByteDisjunction* parenthesesDisjunction;
-                unsigned parenthesesWidth;
-            };
-            QuantifierType quantityType;
-            unsigned quantityMinCount;
-            unsigned quantityMaxCount;
-        } atom;
-        struct {
-            int next;
-            int end;
-            bool onceThrough;
-        } alternative;
-        struct {
-            bool m_bol : 1;
-            bool m_eol : 1;
-        } anchors;
-        unsigned checkInputCount;
-    };
-    unsigned frameLocation;
     bool m_capture : 1;
     bool m_invert : 1;
     unsigned inputPosition;
@@ -377,7 +377,7 @@ public:
     std::unique_ptr<ByteDisjunction> m_body;
     OptionSet<Flags> m_flags;
     // Each BytecodePattern is associated with a RegExp, each RegExp is associated
-    // with a VM.  Cache a pointer to out VM's m_regExpAllocator.
+    // with a VM.  Cache a pointer to our VM's m_regExpAllocator.
     BumpPointerAllocator* m_allocator;
     ConcurrentJSLock* m_lock;
 
index 0f51bd3..a9b5834 100644 (file)
@@ -770,7 +770,7 @@ class YarrGenerator : public YarrJITInfo, private MacroAssembler {
             move(output, reg);
     }
 
-    enum YarrOpCode {
+    enum YarrOpCode : uint8_t {
         // These nodes wrap body alternatives - those in the main disjunction,
         // rather than subpatterns or assertions. These are chained together in
         // a doubly linked list, with a 'begin' node for the first alternative,
@@ -816,8 +816,8 @@ class YarrGenerator : public YarrJITInfo, private MacroAssembler {
     // and JIT compilation data structures.
     struct YarrOp {
         explicit YarrOp(PatternTerm* term)
-            : m_op(OpTerm)
-            , m_term(term)
+            : m_term(term)
+            , m_op(OpTerm)
             , m_isDeadCode(false)
         {
         }
@@ -828,10 +828,6 @@ class YarrGenerator : public YarrJITInfo, private MacroAssembler {
         {
         }
 
-        // The operation, as a YarrOpCode, and also a reference to the PatternTerm.
-        YarrOpCode m_op;
-        PatternTerm* m_term;
-
         // For alternatives, this holds the PatternAlternative and doubly linked
         // references to this alternative's siblings. In the case of the
         // OpBodyAlternativeEnd node at the end of a section of repeating nodes,
@@ -840,6 +836,10 @@ class YarrGenerator : public YarrJITInfo, private MacroAssembler {
         PatternAlternative* m_alternative;
         size_t m_previousOp;
         size_t m_nextOp;
+        
+        // The operation, as a YarrOpCode, and also a reference to the PatternTerm.
+        PatternTerm* m_term;
+        YarrOpCode m_op;
 
         // Used to record a set of Jumps out of the generated code, typically
         // used for jumps out to backtracking code, and a single reentry back
index b0e96cd..55106bb 100644 (file)
@@ -585,7 +585,7 @@ private:
     /*
      * parseCharacterClass():
      *
-     * Helper for parseTokens(); calls dirctly and indirectly (via parseCharacterClassEscape)
+     * Helper for parseTokens(); calls directly and indirectly (via parseCharacterClassEscape)
      * to an instance of CharacterClassParserDelegate, to describe the character class to the
      * delegate.
      */
index 5a2e722..0b7db2e 100644 (file)
@@ -122,14 +122,14 @@ public:
     bool m_anyCharacter : 1;
 };
 
-enum QuantifierType {
+enum QuantifierType : uint8_t {
     QuantifierFixedCount,
     QuantifierGreedy,
     QuantifierNonGreedy,
 };
 
 struct PatternTerm {
-    enum Type {
+    enum Type : uint8_t {
         TypeAssertionBOL,
         TypeAssertionEOL,
         TypeAssertionWordBoundary,
@@ -143,6 +143,9 @@ struct PatternTerm {
     } type;
     bool m_capture :1;
     bool m_invert :1;
+    QuantifierType quantityType;
+    Checked<unsigned> quantityMinCount;
+    Checked<unsigned> quantityMaxCount;
     union {
         UChar32 patternCharacter;
         CharacterClass* characterClass;
@@ -159,9 +162,6 @@ struct PatternTerm {
             bool eolAnchor : 1;
         } anchors;
     };
-    QuantifierType quantityType;
-    Checked<unsigned> quantityMinCount;
-    Checked<unsigned> quantityMaxCount;
     unsigned inputPosition;
     unsigned frameLocation;