Ignore:
Timestamp:
Jun 14, 2008, 11:23:50 PM (17 years ago)
Author:
Darin Adler
Message:

2008-06-14 Darin Adler <Darin Adler>

Rubber stamped by Sam.

  • rename a bunch of local symbols within the regular expression code to follow our usual coding style, and do a few other name tweaks
  • pcre/pcre_compile.cpp: (CompileData::CompileData): (checkEscape): (readRepeatCounts): (compileBranch): (compileBracket): (calculateCompiledPatternLength): (returnError): (jsRegExpCompile):
  • pcre/pcre_exec.cpp: (MatchStack::MatchStack): (MatchStack::canUseStackBufferForNextFrame): (MatchStack::popCurrentFrame): (match): (tryFirstByteOptimization): (tryRequiredByteOptimization): (jsRegExpExecute):
  • pcre/pcre_internal.h:
File:
1 edited

Legend:

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

    r34480 r34560  
    133133
    134134/* The maximum remaining length of subject we are prepared to search for a
    135 req_byte match. */
     135reqByte match. */
    136136
    137137#define REQ_BYTE_MAX 1000
     
    262262    } while (0)
    263263
    264 #define RECURSIVE_MATCH_STARTNG_NEW_GROUP(num, ra, rb) \
     264#define RECURSIVE_MATCH_NEW_GROUP(num, ra, rb) \
    265265    do { \
    266266        stack.pushNewFrame((ra), (rb), RMATCH_WHERE(num)); \
     
    296296*/
    297297
    298 static const unsigned FRAMES_ON_STACK = 16;
     298static const unsigned numFramesOnStack = 16;
    299299
    300300struct MatchStack {
    301301    MatchStack()
    302         : framesEnd(frames + FRAMES_ON_STACK)
     302        : framesEnd(frames + numFramesOnStack)
    303303        , currentFrame(frames)
    304304        , size(1) // match() creates accesses the first frame w/o calling pushNewFrame
    305305    {
    306         ASSERT((sizeof(frames) / sizeof(frames[0])) == FRAMES_ON_STACK);
     306        ASSERT((sizeof(frames) / sizeof(frames[0])) == numFramesOnStack);
    307307    }
    308308   
    309     MatchFrame frames[FRAMES_ON_STACK];
     309    MatchFrame frames[numFramesOnStack];
    310310    MatchFrame* framesEnd;
    311311    MatchFrame* currentFrame;
     
    314314    inline bool canUseStackBufferForNextFrame()
    315315    {
    316         return size < FRAMES_ON_STACK;
     316        return size < numFramesOnStack;
    317317    }
    318318   
     
    343343        MatchFrame* oldFrame = currentFrame;
    344344        currentFrame = currentFrame->previousFrame;
    345         if (size > FRAMES_ON_STACK)
     345        if (size > numFramesOnStack)
    346346            delete oldFrame;
    347347        size--;
     
    474474                DPRINTF(("start bracket 0\n"));
    475475                do {
    476                     RECURSIVE_MATCH_STARTNG_NEW_GROUP(2, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, stack.currentFrame->args.bracketChain);
     476                    RECURSIVE_MATCH_NEW_GROUP(2, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, stack.currentFrame->args.bracketChain);
    477477                    if (isMatch)
    478478                        RRETURN;
     
    504504            BEGIN_OPCODE(ASSERT):
    505505                do {
    506                     RECURSIVE_MATCH_STARTNG_NEW_GROUP(6, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, NULL);
     506                    RECURSIVE_MATCH_NEW_GROUP(6, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, NULL);
    507507                    if (isMatch)
    508508                        break;
     
    524524            BEGIN_OPCODE(ASSERT_NOT):
    525525                do {
    526                     RECURSIVE_MATCH_STARTNG_NEW_GROUP(7, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, NULL);
     526                    RECURSIVE_MATCH_NEW_GROUP(7, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, NULL);
    527527                    if (isMatch)
    528528                        RRETURN_NO_MATCH;
     
    548548            BEGIN_OPCODE(BRAZERO): {
    549549                stack.currentFrame->locals.startOfRepeatingBracket = stack.currentFrame->args.instructionPtr + 1;
    550                 RECURSIVE_MATCH_STARTNG_NEW_GROUP(14, stack.currentFrame->locals.startOfRepeatingBracket, stack.currentFrame->args.bracketChain);
     550                RECURSIVE_MATCH_NEW_GROUP(14, stack.currentFrame->locals.startOfRepeatingBracket, stack.currentFrame->args.bracketChain);
    551551                if (isMatch)
    552552                    RRETURN;
     
    559559                stack.currentFrame->locals.startOfRepeatingBracket = stack.currentFrame->args.instructionPtr + 1;
    560560                advanceToEndOfBracket(stack.currentFrame->locals.startOfRepeatingBracket);
    561                 RECURSIVE_MATCH_STARTNG_NEW_GROUP(15, stack.currentFrame->locals.startOfRepeatingBracket + 1 + LINK_SIZE, stack.currentFrame->args.bracketChain);
     561                RECURSIVE_MATCH_NEW_GROUP(15, stack.currentFrame->locals.startOfRepeatingBracket + 1 + LINK_SIZE, stack.currentFrame->args.bracketChain);
    562562                if (isMatch)
    563563                    RRETURN;
     
    640640                    if (isMatch)
    641641                        RRETURN;
    642                     RECURSIVE_MATCH_STARTNG_NEW_GROUP(17, stack.currentFrame->locals.instructionPtrAtStartOfOnce, stack.currentFrame->args.bracketChain);
     642                    RECURSIVE_MATCH_NEW_GROUP(17, stack.currentFrame->locals.instructionPtrAtStartOfOnce, stack.currentFrame->args.bracketChain);
    643643                    if (isMatch)
    644644                        RRETURN;
    645645                } else { /* OP_KETRMAX */
    646                     RECURSIVE_MATCH_STARTNG_NEW_GROUP(18, stack.currentFrame->locals.instructionPtrAtStartOfOnce, stack.currentFrame->args.bracketChain);
     646                    RECURSIVE_MATCH_NEW_GROUP(18, stack.currentFrame->locals.instructionPtrAtStartOfOnce, stack.currentFrame->args.bracketChain);
    647647                    if (isMatch)
    648648                        RRETURN;
     
    17361736                   
    17371737                    do {
    1738                         RECURSIVE_MATCH_STARTNG_NEW_GROUP(1, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, stack.currentFrame->args.bracketChain);
     1738                        RECURSIVE_MATCH_NEW_GROUP(1, stack.currentFrame->args.instructionPtr + 1 + LINK_SIZE, stack.currentFrame->args.bracketChain);
    17391739                        if (isMatch)
    17401740                            RRETURN;
     
    18231823  options         option bits
    18241824  offsets         points to a vector of ints to be filled in with offsets
    1825   offsetcount     the number of elements in the vector
     1825  offsetCount     the number of elements in the vector
    18261826
    18271827Returns:          > 0 => success; value is the number of elements filled in
     
    18311831*/
    18321832
    1833 static void tryFirstByteOptimization(const UChar*& subjectPtr, const UChar* endSubject, int first_byte, bool first_byte_caseless, bool useMultiLineFirstCharOptimization, const UChar* originalSubjectStart)
     1833static void tryFirstByteOptimization(const UChar*& subjectPtr, const UChar* endSubject, int firstByte, bool firstByteIsCaseless, bool useMultiLineFirstCharOptimization, const UChar* originalSubjectStart)
    18341834{
    1835     // If first_byte is set, try scanning to the first instance of that byte
     1835    // If firstByte is set, try scanning to the first instance of that byte
    18361836    // no need to try and match against any earlier part of the subject string.
    1837     if (first_byte >= 0) {
    1838         UChar first_char = first_byte;
    1839         if (first_byte_caseless)
     1837    if (firstByte >= 0) {
     1838        UChar firstChar = firstByte;
     1839        if (firstByteIsCaseless)
    18401840            while (subjectPtr < endSubject) {
    18411841                int c = *subjectPtr;
    18421842                if (c > 127)
    18431843                    break;
    1844                 if (toLowerCase(c) == first_char)
     1844                if (toLowerCase(c) == firstChar)
    18451845                    break;
    18461846                subjectPtr++;
    18471847            }
    18481848        else {
    1849             while (subjectPtr < endSubject && *subjectPtr != first_char)
     1849            while (subjectPtr < endSubject && *subjectPtr != firstChar)
    18501850                subjectPtr++;
    18511851        }
     
    18601860}
    18611861
    1862 static bool tryRequiredByteOptimization(const UChar*& subjectPtr, const UChar* endSubject, int req_byte, int req_byte2, bool req_byte_caseless, bool hasFirstByte, const UChar*& reqBytePtr)
     1862static bool tryRequiredByteOptimization(const UChar*& subjectPtr, const UChar* endSubject, int reqByte, int reqByte2, bool reqByteIsCaseless, bool hasFirstByte, const UChar*& reqBytePtr)
    18631863{
    1864     /* If req_byte is set, we know that that character must appear in the subject
    1865      for the match to succeed. If the first character is set, req_byte must be
     1864    /* If reqByte is set, we know that that character must appear in the subject
     1865     for the match to succeed. If the first character is set, reqByte must be
    18661866     later in the subject; otherwise the test starts at the match point. This
    18671867     optimization can save a huge amount of backtracking in patterns with nested
     
    18761876    */
    18771877
    1878     if (req_byte >= 0 && endSubject - subjectPtr < REQ_BYTE_MAX) {
     1878    if (reqByte >= 0 && endSubject - subjectPtr < REQ_BYTE_MAX) {
    18791879        const UChar* p = subjectPtr + (hasFirstByte ? 1 : 0);
    18801880
     
    18831883
    18841884        if (p > reqBytePtr) {
    1885             if (req_byte_caseless) {
     1885            if (reqByteIsCaseless) {
    18861886                while (p < endSubject) {
    18871887                    int pp = *p++;
    1888                     if (pp == req_byte || pp == req_byte2) {
     1888                    if (pp == reqByte || pp == reqByte2) {
    18891889                        p--;
    18901890                        break;
     
    18931893            } else {
    18941894                while (p < endSubject) {
    1895                     if (*p++ == req_byte) {
     1895                    if (*p++ == reqByte) {
    18961896                        p--;
    18971897                        break;
     
    19171917int jsRegExpExecute(const JSRegExp* re,
    19181918                    const UChar* subject, int length, int start_offset, int* offsets,
    1919                     int offsetcount)
     1919                    int offsetCount)
    19201920{
    19211921    ASSERT(re);
    19221922    ASSERT(subject);
    1923     ASSERT(offsetcount >= 0);
    1924     ASSERT(offsets || offsetcount == 0);
     1923    ASSERT(offsetCount >= 0);
     1924    ASSERT(offsets || offsetCount == 0);
    19251925   
    19261926    MatchData matchBlock;
     
    19371937     of 3. */
    19381938   
    1939     int ocount = offsetcount - (offsetcount % 3);
     1939    int ocount = offsetCount - (offsetCount % 3);
    19401940   
    19411941    // FIXME: This is lame that we have to second-guess our caller here.
    19421942    // The API should change to either fail-hard when we don't have enough offset space
    19431943    // or that we shouldn't ask our callers to pre-allocate in the first place.
    1944     bool using_temporary_offsets = false;
    1945     if (re->top_backref > 0 && re->top_backref >= ocount/3) {
    1946         ocount = re->top_backref * 3 + 3;
     1944    bool usingTemporaryOffsets = false;
     1945    if (re->topBackref > 0 && re->topBackref >= ocount/3) {
     1946        ocount = re->topBackref * 3 + 3;
    19471947        matchBlock.offsetVector = new int[ocount];
    19481948        if (!matchBlock.offsetVector)
    19491949            return JSRegExpErrorNoMemory;
    1950         using_temporary_offsets = true;
     1950        usingTemporaryOffsets = true;
    19511951    } else
    19521952        matchBlock.offsetVector = offsets;
     
    19601960     in the pattern. */
    19611961   
    1962     int resetcount = 2 + re->top_bracket * 2;
    1963     if (resetcount > offsetcount)
    1964         resetcount = ocount;
     1962    int resetCount = 2 + re->topBracket * 2;
     1963    if (resetCount > offsetCount)
     1964        resetCount = ocount;
    19651965   
    19661966    /* Reset the working variable associated with each extraction. These should
     
    19701970    if (matchBlock.offsetVector) {
    19711971        int* iptr = matchBlock.offsetVector + ocount;
    1972         int* iend = iptr - resetcount/2 + 1;
     1972        int* iend = iptr - resetCount/2 + 1;
    19731973        while (--iptr >= iend)
    19741974            *iptr = -1;
    19751975    }
    19761976   
    1977     /* Set up the first character to match, if available. The first_byte value is
     1977    /* Set up the first character to match, if available. The firstByte value is
    19781978     never set for an anchored regular expression, but the anchoring may be forced
    19791979     at run time, so we have to test for anchoring. The first char may be unset for
     
    19811981     studied, there may be a bitmap of possible first characters. */
    19821982   
    1983     bool first_byte_caseless = false;
    1984     int first_byte = -1;
     1983    bool firstByteIsCaseless = false;
     1984    int firstByte = -1;
    19851985    if (re->options & UseFirstByteOptimizationOption) {
    1986         first_byte = re->first_byte & 255;
    1987         if ((first_byte_caseless = (re->first_byte & REQ_IGNORE_CASE)))
    1988             first_byte = toLowerCase(first_byte);
     1986        firstByte = re->firstByte & 255;
     1987        if ((firstByteIsCaseless = (re->firstByte & REQ_IGNORE_CASE)))
     1988            firstByte = toLowerCase(firstByte);
    19891989    }
    19901990   
     
    19921992     character" set. */
    19931993   
    1994     bool req_byte_caseless = false;
    1995     int req_byte = -1;
    1996     int req_byte2 = -1;
     1994    bool reqByteIsCaseless = false;
     1995    int reqByte = -1;
     1996    int reqByte2 = -1;
    19971997    if (re->options & UseRequiredByteOptimizationOption) {
    1998         req_byte = re->req_byte & 255; // FIXME: This optimization could be made to work for UTF16 chars as well...
    1999         req_byte_caseless = (re->req_byte & REQ_IGNORE_CASE);
    2000         req_byte2 = flipCase(req_byte);
     1998        reqByte = re->reqByte & 255; // FIXME: This optimization could be made to work for UTF16 chars as well...
     1999        reqByteIsCaseless = (re->reqByte & REQ_IGNORE_CASE);
     2000        reqByte2 = flipCase(reqByte);
    20012001    }
    20022002   
     
    20122012        if (matchBlock.offsetVector) {
    20132013            int* iptr = matchBlock.offsetVector;
    2014             int* iend = iptr + resetcount;
     2014            int* iend = iptr + resetCount;
    20152015            while (iptr < iend)
    20162016                *iptr++ = -1;
    20172017        }
    20182018       
    2019         tryFirstByteOptimization(startMatch, endSubject, first_byte, first_byte_caseless, useMultiLineFirstCharOptimization, matchBlock.startSubject + start_offset);
    2020         if (tryRequiredByteOptimization(startMatch, endSubject, req_byte, req_byte2, req_byte_caseless, first_byte >= 0, reqBytePtr))
     2019        tryFirstByteOptimization(startMatch, endSubject, firstByte, firstByteIsCaseless, useMultiLineFirstCharOptimization, matchBlock.startSubject + start_offset);
     2020        if (tryRequiredByteOptimization(startMatch, endSubject, reqByte, reqByte2, reqByteIsCaseless, firstByte >= 0, reqBytePtr))
    20212021            break;
    20222022               
     
    20492049         necessary */
    20502050       
    2051         if (using_temporary_offsets) {
    2052             if (offsetcount >= 4) {
    2053                 memcpy(offsets + 2, matchBlock.offsetVector + 2, (offsetcount - 2) * sizeof(int));
     2051        if (usingTemporaryOffsets) {
     2052            if (offsetCount >= 4) {
     2053                memcpy(offsets + 2, matchBlock.offsetVector + 2, (offsetCount - 2) * sizeof(int));
    20542054                DPRINTF(("Copied offsets from temporary memory\n"));
    20552055            }
    2056             if (matchBlock.endOffsetTop > offsetcount)
     2056            if (matchBlock.endOffsetTop > offsetCount)
    20572057                matchBlock.offsetOverflow = true;
    20582058           
     
    20632063        returnCode = matchBlock.offsetOverflow ? 0 : matchBlock.endOffsetTop / 2;
    20642064       
    2065         if (offsetcount < 2)
     2065        if (offsetCount < 2)
    20662066            returnCode = 0;
    20672067        else {
     
    20742074    } while (!(re->options & IsAnchoredOption) && startMatch <= endSubject);
    20752075   
    2076     if (using_temporary_offsets) {
     2076    if (usingTemporaryOffsets) {
    20772077        DPRINTF(("Freeing temporary memory\n"));
    20782078        delete [] matchBlock.offsetVector;
Note: See TracChangeset for help on using the changeset viewer.