Changeset 31454 in webkit for trunk/JavaScriptCore/pcre


Ignore:
Timestamp:
Mar 31, 2008, 1:01:09 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by darin.

Make matching of regexps using much faster
http://bugs.webkit.org/show_bug.cgi?id=18086

  • pcre/pcre_compile.cpp: (compileBranch): (branchNeedsLineStart):
  • pcre/pcre_exec.cpp: (match): (jsRegExpExecute):
  • pcre/pcre_internal.h:
Location:
trunk/JavaScriptCore/pcre
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/pcre/pcre_compile.cpp

    r31388 r31454  
    637637            /* Handle single-character metacharacters. In multiline mode, ^ disables
    638638             the setting of any following char as a first character. */
    639                
     639
    640640            case '^':
    641641                if (options & MatchAcrossMultipleLinesOption) {
    642642                    if (firstbyte == REQ_UNSET)
    643643                        firstbyte = REQ_NONE;
    644                 }
     644                    *code++ = OP_BOL;
     645                } else
     646                    *code++ = OP_CIRC;
    645647                previous = NULL;
    646                 *code++ = OP_CIRC;
    647648                break;
    648                
     649
    649650            case '$':
    650651                previous = NULL;
    651                 *code++ = OP_DOLL;
     652                if (options & MatchAcrossMultipleLinesOption)
     653                  *code++ = OP_EOL;
     654                else
     655                  *code++ = OP_DOLL;
    652656                break;
    653                
     657
    654658            /* There can never be a first char if '.' is first, whatever happens about
    655659             repeats. The value of reqbyte doesn't change either. */
    656                
     660
    657661            case '.':
    658662                if (firstbyte == REQ_UNSET)
     
    19051909
    19061910    /* Explicit ^ */
    1907     return op == OP_CIRC;
     1911    return op == OP_CIRC || op == OP_BOL;
    19081912}
    19091913
  • trunk/JavaScriptCore/pcre/pcre_exec.cpp

    r31048 r31454  
    653653                RRETURN;
    654654               
    655             /* Start of subject, or after internal newline if multiline. */
    656                
     655            /* Start of subject. */
     656
    657657            BEGIN_OPCODE(CIRC):
    658                 if (stack.currentFrame->args.subjectPtr != md.startSubject && (!md.multiline || !isNewline(stack.currentFrame->args.subjectPtr[-1])))
     658                if (stack.currentFrame->args.subjectPtr != md.startSubject)
    659659                    RRETURN_NO_MATCH;
    660660                stack.currentFrame->args.instructionPtr++;
    661661                NEXT_OPCODE;
    662                
    663             /* End of subject, or before internal newline if multiline. */
    664                
     662
     663            /* After internal newline if multiline. */
     664
     665            BEGIN_OPCODE(BOL):
     666                if (stack.currentFrame->args.subjectPtr != md.startSubject && !isNewline(stack.currentFrame->args.subjectPtr[-1]))
     667                    RRETURN_NO_MATCH;
     668                stack.currentFrame->args.instructionPtr++;
     669                NEXT_OPCODE;
     670
     671            /* End of subject. */
     672
    665673            BEGIN_OPCODE(DOLL):
    666                 if (stack.currentFrame->args.subjectPtr < md.endSubject && (!md.multiline || !isNewline(*stack.currentFrame->args.subjectPtr)))
     674                if (stack.currentFrame->args.subjectPtr < md.endSubject)
     675                    RRETURN_NO_MATCH;
     676                stack.currentFrame->args.instructionPtr++;
     677                NEXT_OPCODE;
     678
     679            /* Before internal newline if multiline. */
     680
     681            BEGIN_OPCODE(EOL):
     682                if (stack.currentFrame->args.subjectPtr < md.endSubject && !isNewline(*stack.currentFrame->args.subjectPtr))
    667683                    RRETURN_NO_MATCH;
    668684                stack.currentFrame->args.instructionPtr++;
     
    20552071        DPRINTF((">>>> returning %d\n", returnCode));
    20562072        return returnCode;
    2057     } while (startMatch <= endSubject);
     2073    } while (!(re->options & IsAnchoredOption) && startMatch <= endSubject);
    20582074   
    20592075    if (using_temporary_offsets) {
  • trunk/JavaScriptCore/pcre/pcre_internal.h

    r28793 r31454  
    232232    macro(CIRC) \
    233233    macro(DOLL) \
     234    macro(BOL) \
     235    macro(EOL) \
    234236    macro(CHAR) \
    235237    macro(CHAR_IGNORING_CASE) \
Note: See TracChangeset for help on using the changeset viewer.