Changeset 72781 in webkit for trunk/JavaScriptCore/yarr/RegexCompiler.cpp
- Timestamp:
- Nov 28, 2010, 4:45:16 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/yarr/RegexCompiler.cpp
r72489 r72781 668 668 // Note: for fixed once parentheses we will ensure at least the minimum is available; others are on their own. 669 669 term.frameLocation = currentCallFrameSize; 670 if ((term.quantityCount == 1) && !term.parentheses.isCopy) { 671 if (term.quantityType == QuantifierFixedCount) { 672 currentCallFrameSize = setupDisjunctionOffsets(term.parentheses.disjunction, currentCallFrameSize, currentInputPosition); 670 if (term.quantityCount == 1 && !term.parentheses.isCopy) { 671 if (term.quantityType != QuantifierFixedCount) 672 currentCallFrameSize += RegexStackSpaceForBackTrackInfoParenthesesOnce; 673 currentCallFrameSize = setupDisjunctionOffsets(term.parentheses.disjunction, currentCallFrameSize, currentInputPosition); 674 // If quantity is fixed, then pre-check its minimum size. 675 if (term.quantityType == QuantifierFixedCount) 673 676 currentInputPosition += term.parentheses.disjunction->m_minimumSize; 674 } else {675 currentCallFrameSize += RegexStackSpaceForBackTrackInfoParenthesesOnce;676 currentCallFrameSize = setupDisjunctionOffsets(term.parentheses.disjunction, currentCallFrameSize, currentInputPosition);677 }677 term.inputPosition = currentInputPosition; 678 } else if (term.parentheses.isTerminal) { 679 currentCallFrameSize += RegexStackSpaceForBackTrackInfoParenthesesTerminal; 680 currentCallFrameSize = setupDisjunctionOffsets(term.parentheses.disjunction, currentCallFrameSize, currentInputPosition); 678 681 term.inputPosition = currentInputPosition; 679 682 } else { … … 729 732 } 730 733 734 // This optimization identifies sets of parentheses that we will never need to backtrack. 735 // In these cases we do not need to store state from prior iterations. 736 // We can presently avoid backtracking for: 737 // * a set of parens at the end of the regular expression (last term in any of the alternatives of the main body disjunction). 738 // * where the parens are non-capturing, and quantified unbounded greedy (*). 739 // * where the parens do not contain any capturing subpatterns. 740 void checkForTerminalParentheses() 741 { 742 // This check is much too crude; should be just checking whether the candidate 743 // node contains nested capturing subpatterns, not the whole expression! 744 if (m_pattern.m_numSubpatterns) 745 return; 746 747 Vector<PatternAlternative*>& alternatives = m_pattern.m_body->m_alternatives; 748 for (unsigned i =0; i < alternatives.size(); ++i) { 749 Vector<PatternTerm>& terms = alternatives[i]->m_terms; 750 if (terms.size()) { 751 PatternTerm& term = terms.last(); 752 if (term.type == PatternTerm::TypeParenthesesSubpattern 753 && term.quantityType == QuantifierGreedy 754 && term.quantityCount == UINT_MAX 755 && !term.capture()) 756 term.parentheses.isTerminal = true; 757 } 758 } 759 } 760 731 761 void optimizeBOL() 732 762 { … … 931 961 } 932 962 963 constructor.checkForTerminalParentheses(); 933 964 constructor.optimizeBOL(); 934 965
Note:
See TracChangeset
for help on using the changeset viewer.