Changeset 90962 in webkit for trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp
- Timestamp:
- Jul 13, 2011, 4:05:40 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp
r87109 r90962 583 583 currentCallFrameSize = setupDisjunctionOffsets(term.parentheses.disjunction, currentCallFrameSize + YarrStackSpaceForBackTrackInfoParentheticalAssertion, currentInputPosition); 584 584 break; 585 586 case PatternTerm::TypeDotStarEnclosure: 587 alternative->m_hasFixedSize = false; 588 term.inputPosition = initialInputPosition; 589 break; 585 590 } 586 591 } … … 676 681 } 677 682 683 bool containsCapturingTerms(PatternAlternative* alternative, size_t firstTermIndex, size_t lastTermIndex) 684 { 685 Vector<PatternTerm>& terms = alternative->m_terms; 686 687 for (size_t termIndex = firstTermIndex; termIndex <= lastTermIndex; ++termIndex) { 688 PatternTerm& term = terms[termIndex]; 689 690 if (term.m_capture) 691 return true; 692 693 if (term.type == PatternTerm::TypeParenthesesSubpattern) { 694 PatternDisjunction* nestedDisjunction = term.parentheses.disjunction; 695 for (unsigned alt = 0; alt < nestedDisjunction->m_alternatives.size(); ++alt) { 696 if (containsCapturingTerms(nestedDisjunction->m_alternatives[alt], 0, nestedDisjunction->m_alternatives[alt]->m_terms.size() - 1)) 697 return true; 698 } 699 } 700 } 701 702 return false; 703 } 704 705 // This optimization identifies alternatives in the form of 706 // [^].*[?]<expression>.*[$] for expressions that don't have any 707 // capturing terms. The alternative is changed to <expression> 708 // followed by processing of the dot stars to find and adjust the 709 // beginning and the end of the match. 710 void optimizeDotStarWrappedExpressions() 711 { 712 Vector<PatternAlternative*>& alternatives = m_pattern.m_body->m_alternatives; 713 if (alternatives.size() != 1) 714 return; 715 716 PatternAlternative* alternative = alternatives[0]; 717 Vector<PatternTerm>& terms = alternative->m_terms; 718 if (terms.size() >= 3) { 719 bool startsWithBOL = false; 720 bool endsWithEOL = false; 721 size_t termIndex, firstExpressionTerm, lastExpressionTerm; 722 723 termIndex = 0; 724 if (terms[termIndex].type == PatternTerm::TypeAssertionBOL) { 725 startsWithBOL = true; 726 ++termIndex; 727 } 728 729 PatternTerm& firstNonAnchorTerm = terms[termIndex]; 730 if ((firstNonAnchorTerm.type != PatternTerm::TypeCharacterClass) || (firstNonAnchorTerm.characterClass != m_pattern.newlineCharacterClass()) || !((firstNonAnchorTerm.quantityType == QuantifierGreedy) || (firstNonAnchorTerm.quantityType == QuantifierNonGreedy))) 731 return; 732 733 firstExpressionTerm = termIndex + 1; 734 735 termIndex = terms.size() - 1; 736 if (terms[termIndex].type == PatternTerm::TypeAssertionEOL) { 737 endsWithEOL = true; 738 --termIndex; 739 } 740 741 PatternTerm& lastNonAnchorTerm = terms[termIndex]; 742 if ((lastNonAnchorTerm.type != PatternTerm::TypeCharacterClass) || (lastNonAnchorTerm.characterClass != m_pattern.newlineCharacterClass()) || (lastNonAnchorTerm.quantityType != QuantifierGreedy)) 743 return; 744 745 lastExpressionTerm = termIndex - 1; 746 747 if (firstExpressionTerm > lastExpressionTerm) 748 return; 749 750 if (!containsCapturingTerms(alternative, firstExpressionTerm, lastExpressionTerm)) { 751 for (termIndex = terms.size() - 1; termIndex > lastExpressionTerm; --termIndex) 752 terms.remove(termIndex); 753 754 for (termIndex = firstExpressionTerm; termIndex > 0; --termIndex) 755 terms.remove(termIndex - 1); 756 757 terms.append(PatternTerm(startsWithBOL, endsWithEOL)); 758 759 m_pattern.m_containsBOL = false; 760 } 761 } 762 } 763 678 764 private: 679 765 YarrPattern& m_pattern; … … 709 795 710 796 constructor.checkForTerminalParentheses(); 797 constructor.optimizeDotStarWrappedExpressions(); 711 798 constructor.optimizeBOL(); 712 799
Note:
See TracChangeset
for help on using the changeset viewer.