Changeset 76502 in webkit


Ignore:
Timestamp:
Jan 24, 2011 3:52:43 AM (13 years ago)
Author:
pvarga@webkit.org
Message:

2011-01-24 Peter Varga <pvarga@inf.u-szeged.hu>

Reviewed by Oliver Hunt.

Optimize regex patterns which contain empty alternatives
https://bugs.webkit.org/show_bug.cgi?id=51395

Eliminate the empty alternatives from the regex pattern and convert it to do
the matching in an easier way.

  • fast/regex/script-tests/slow.js:
  • fast/regex/slow-expected.txt:

2011-01-24 Peter Varga <pvarga@webkit.org>

Reviewed by Oliver Hunt.

Optimize regex patterns which contain empty alternatives
https://bugs.webkit.org/show_bug.cgi?id=51395

Eliminate the empty alternatives from the regex pattern and convert it to do
the matching in an easier way.

  • yarr/YarrPattern.cpp: (JSC::Yarr::YarrPatternConstructor::atomParenthesesEnd):
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r76500 r76502  
     12011-01-24  Peter Varga  <pvarga@inf.u-szeged.hu>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Optimize regex patterns which contain empty alternatives
     6        https://bugs.webkit.org/show_bug.cgi?id=51395
     7
     8        Eliminate the empty alternatives from the regex pattern and convert it to do
     9        the matching in an easier way.
     10
     11        * fast/regex/script-tests/slow.js:
     12        * fast/regex/slow-expected.txt:
     13
    1142011-01-24  Pavel Podivilov  <podivilov@chromium.org>
    215
  • trunk/LayoutTests/fast/regex/script-tests/slow.js

    r48552 r76502  
    33);
    44
    5 shouldBe('/(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/")', 'false');
     5shouldBe('/(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/")', 'true');
    66
    77var successfullyParsed = true;
  • trunk/LayoutTests/fast/regex/slow-expected.txt

    r28833 r76502  
    44
    55
    6 PASS /(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/") is false
     6PASS /(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/") is true
    77PASS successfullyParsed is true
    88
  • trunk/Source/JavaScriptCore/ChangeLog

    r76496 r76502  
     12011-01-24  Peter Varga  <pvarga@webkit.org>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Optimize regex patterns which contain empty alternatives
     6        https://bugs.webkit.org/show_bug.cgi?id=51395
     7
     8        Eliminate the empty alternatives from the regex pattern and convert it to do
     9        the matching in an easier way.
     10
     11        * yarr/YarrPattern.cpp:
     12        (JSC::Yarr::YarrPatternConstructor::atomParenthesesEnd):
     13
    1142011-01-24  Andras Becsi  <abecsi@webkit.org>
    215
  • trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp

    r75602 r76502  
    489489
    490490        PatternTerm& lastTerm = m_alternative->lastTerm();
    491        
     491
    492492        unsigned numParenAlternatives = parenthesesDisjunction->m_alternatives.size();
    493493        unsigned numBOLAnchoredAlts = 0;
    494         // Bubble up BOL flags
     494        bool containsEmptyAlternative = false;
     495
    495496        for (unsigned i = 0; i < numParenAlternatives; i++) {
     497            if (!parenthesesDisjunction->m_alternatives[i]->m_terms.size() && numParenAlternatives > 1) {
     498                parenthesesDisjunction->m_alternatives.remove(i);
     499                --numParenAlternatives;
     500
     501                containsEmptyAlternative = true;
     502                continue;
     503            }
     504
     505            // Bubble up BOL flags
    496506            if (parenthesesDisjunction->m_alternatives[i]->m_startsWithBOL)
    497507                numBOLAnchoredAlts++;
    498508        }
    499        
     509
    500510        if (numBOLAnchoredAlts) {
    501511            m_alternative->m_containsBOL = true;
     
    504514                m_alternative->m_startsWithBOL = true;
    505515        }
    506        
     516
    507517        lastTerm.parentheses.lastSubpatternId = m_pattern.m_numSubpatterns;
    508518        m_invertParentheticalAssertion = false;
     519
     520        if (containsEmptyAlternative) {
     521            // Backup and remove the current disjunction's alternatives.
     522            Vector<PatternAlternative*> alternatives;
     523            alternatives.append(parenthesesDisjunction->m_alternatives);
     524            parenthesesDisjunction->m_alternatives.clear();
     525            PatternAlternative* alternative = parenthesesDisjunction->addNewAlternative();
     526
     527            // Insert a new non-capturing parentheses.
     528            unsigned subpatternId = m_pattern.m_numSubpatterns + 1;
     529            PatternDisjunction* newDisjunction = new PatternDisjunction(alternative);
     530            m_pattern.m_disjunctions.append(newDisjunction);
     531            alternative->m_terms.append(PatternTerm(PatternTerm::TypeParenthesesSubpattern, subpatternId, newDisjunction, false, false));
     532            newDisjunction->m_alternatives.append(alternatives);
     533
     534            // Set the quantifier of the new parentheses to '?' and set the inherited properties.
     535            PatternTerm& disjunctionTerm = alternative->lastTerm();
     536            disjunctionTerm.quantify(1, QuantifierGreedy);
     537            disjunctionTerm.parentheses.lastSubpatternId = m_pattern.m_numSubpatterns;
     538            alternative->m_containsBOL = m_alternative->m_containsBOL;
     539            alternative->m_startsWithBOL = m_alternative->m_startsWithBOL;
     540        }
    509541    }
    510542
Note: See TracChangeset for help on using the changeset viewer.