Changeset 28164 in webkit


Ignore:
Timestamp:
Nov 29, 2007 3:25:16 AM (16 years ago)
Author:
eric@webkit.org
Message:

2007-11-24 Eric Seidel <eric@webkit.org>

Reviewed by Maciej.

Remove redundant match_call_count and move recursion check out of super-hot code path
SunSpider says this is at least an 8% speedup for regexp.

  • pcre/pcre_exec.cpp: (MatchStack::MatchStack): (MatchStack::pushNewFrame): (MatchStack::popCurrentFrame): (MatchStack::popAllFrames): (match): (jsRegExpExecute):
  • pcre/pcre_internal.h:
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r28163 r28164  
    2020        (MatchStack::pushNewFrame):
    2121        (match):
     22
     232007-11-24  Eric Seidel  <eric@webkit.org>
     24
     25        Reviewed by Maciej.
     26
     27        Remove redundant match_call_count and move recursion check out of super-hot code path
     28        SunSpider says this is at least an 8% speedup for regexp.
     29
     30        * pcre/pcre_exec.cpp:
     31        (MatchStack::MatchStack):
     32        (MatchStack::pushNewFrame):
     33        (MatchStack::popCurrentFrame):
     34        (MatchStack::popAllFrames):
     35        (match):
     36        (jsRegExpExecute):
     37        * pcre/pcre_internal.h:
    2238
    23392007-11-24  Eric Seidel  <eric@webkit.org>
  • trunk/JavaScriptCore/pcre/pcre_exec.cpp

    r28163 r28164  
    125125
    126126struct MatchData {
    127   unsigned long int match_call_count;
    128127  int*   offset_vector;         /* Offset vector */
    129128  int    offset_end;            /* One past the end */
     
    285284    stack.pushNewFrame((ra), (rb), RMATCH_WHERE(num)); \
    286285    is_group_start = (rc);\
    287     ++rdepth;\
     286    if (stack.size >= MATCH_LIMIT_RECURSION) \
     287        return matchError(JSRegExpErrorRecursionLimit, stack); \
    288288    DPRINTF(("restarting from line %d\n", __LINE__));\
    289289    goto RECURSE;\
    290290RRETURN_##num:\
    291291    stack.popCurrentFrame(); \
    292     --rdepth;\
    293292    DPRINTF(("did a goto back to line %d\n", __LINE__));\
    294293  }
     
    330329        framesEnd = frames + sizeof(frames) / sizeof(frames[0]);
    331330        currentFrame = frames;
     331        size = 0;
    332332    }
    333333   
     
    338338    MatchFrame* framesEnd;
    339339    MatchFrame* currentFrame;
     340    unsigned size;
    340341   
    341342    inline bool canUseStackBufferForNextFrame()
     
    361362        newframe->args.eptrb = eptrb;
    362363        newframe->returnLocation = returnLocation;
     364        size++;
    363365
    364366        currentFrame = newframe;
     
    376378        if (!frameIsStackAllocated(oldFrame))
    377379            delete oldFrame;
     380        size--;
    378381    }
    379382
    380     void unrollAnyHeapAllocatedFrames()
     383    void popAllFrames()
    381384    {
    382         while (!frameIsStackAllocated(currentFrame)) {
    383             MatchFrame* oldFrame = currentFrame;
    384             currentFrame = currentFrame->previousFrame;
    385             delete oldFrame;
    386         }
     385        while (size)
     386            popCurrentFrame();
    387387    }
    388388};
     
    390390static int matchError(int errorCode, MatchStack& stack)
    391391{
    392     stack.unrollAnyHeapAllocatedFrames();
     392    stack.popAllFrames();
    393393    return errorCode;
    394394}
     
    418418    int c;
    419419   
    420     unsigned rdepth = 0;
    421    
    422420    bool cur_is_word;
    423421    bool prev_is_word;
     
    464462     complicated macro. It has to be used in one particular way. This shouldn't,
    465463     however, impact performance when true recursion is being used. */
    466    
    467     /* First check that we haven't called match() too many times, or that we
    468      haven't exceeded the recursive call limit. */
    469    
    470     if (md.match_call_count++ >= MATCH_LIMIT)
    471         return matchError(JSRegExpErrorMatchLimit, stack);
    472     if (rdepth >= MATCH_LIMIT_RECURSION)
    473         return matchError(JSRegExpErrorRecursionLimit, stack);
    474464   
    475465    /* At the start of a bracketed group, add the current subject pointer to the
     
    22662256         if certain parts of the pattern were not used. */
    22672257       
    2268         match_block.match_call_count = 0;
    2269        
    2270        
    22712258        /* The code starts after the JSRegExp block and the capture name table. */
    22722259        const uschar* start_code = (const uschar*)(re + 1);
  • trunk/JavaScriptCore/pcre/pcre_internal.h

    r28163 r28164  
    8686#define LINK_SIZE   2
    8787
    88 /* The value of MATCH_LIMIT determines the default number of times the internal
    89 match() function can be called during a single execution of pcre_exec(). There
    90 is a runtime interface for setting a different limit. The limit exists in order
    91 to catch runaway regular expressions that take for ever to determine that they
    92 do not match. The default is set very large so that it does not accidentally
    93 catch legitimate cases. On systems that support it, "configure" can be used to
    94 override this default default. */
    95 
    96 #define MATCH_LIMIT 10000000
    97 
    98 /* The above limit applies to all calls of match(), whether or not they
    99 increase the recursion depth. In some environments it is desirable to limit the
    100 depth of recursive calls of match() more strictly, in order to restrict the
    101 maximum amount of stack (or heap, if NO_RECURSE is defined) that is used. The
    102 value of MATCH_LIMIT_RECURSION applies only to recursive calls of match(). To
    103 have any useful effect, it must be less than the value of MATCH_LIMIT. There is
    104 a runtime method for setting a different limit. On systems that support it,
    105 "configure" can be used to override this default default. */
    106 
    107 #define MATCH_LIMIT_RECURSION MATCH_LIMIT
     88/* The below limit restricts the number of recursive match calls in order to
     89limit the maximum amount of stack (or heap, if NO_RECURSE is defined) that is used. The
     90value of MATCH_LIMIT_RECURSION applies only to recursive calls of match(). */
     91
     92#define MATCH_LIMIT_RECURSION 10000000
    10893
    10994#define _pcre_default_tables kjs_pcre_default_tables
Note: See TracChangeset for help on using the changeset viewer.