Changeset 27830 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 15, 2007, 4:17:54 PM (18 years ago)
Author:
[email protected]
Message:

2007-11-15 Eric Seidel <[email protected]>

Reviewed by Sam.

Abstract most of RMATCH into MatchStack functions.

SunSpider claims this, combined with the last 2 patches was a 1% speedup, 10% for dna-regexp.

  • pcre/pcre_exec.cpp: (MatchStack::canUseStackBufferForNextFrame): (MatchStack::allocateNextFrame): (MatchStack::pushNewFrame): (MatchStack::frameIsStackAllocated): (MatchStack::popCurrentFrame): (MatchStack::unrollAnyHeapAllocatedFrames): (match):
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r27829 r27830  
    33        Reviewed by Sam.
    44
     5        Abstract most of RMATCH into MatchStack functions.
     6       
     7        SunSpider claims this, combined with the last 2 patches was a 1% speedup, 10% for dna-regexp.
     8
     9        * pcre/pcre_exec.cpp:
     10        (MatchStack::canUseStackBufferForNextFrame):
     11        (MatchStack::allocateNextFrame):
     12        (MatchStack::pushNewFrame):
     13        (MatchStack::frameIsStackAllocated):
     14        (MatchStack::popCurrentFrame):
     15        (MatchStack::unrollAnyHeapAllocatedFrames):
     16        (match):
     17
     182007-11-15  Eric Seidel  <[email protected]>
     19
     20        Reviewed by Sam.
     21
    522        Remove RETURN_ERROR, add MatchStack
    6 
     23       
    724        * pcre/pcre_exec.cpp:
    825        (MatchStack::MatchStack):
     
    1027        (matchError):
    1128        (match):
    12 
     29       
    13302007-11-15  Eric Seidel  <[email protected]>
    1431
  • trunk/JavaScriptCore/pcre/pcre_exec.cpp

    r27829 r27830  
    7373/* Structure for remembering the local variables in a private frame */
    7474
     75
     76
     77#ifndef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
     78typedef int ReturnLocation;
     79#else
     80typedef void* ReturnLocation;
     81#endif
     82
    7583typedef struct matchframe {
    76   /* Where to jump back to */
    77 #ifndef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
    78   int where;
    79 #else
    80   void *where;
    81 #endif
    82 
    83   struct matchframe *prevframe;
     84  ReturnLocation returnLocation;
     85
     86  struct matchframe* prevframe;
    8487
    8588  /* Function arguments that may change */
    8689
    8790  const pcre_uchar *eptr;
    88   const uschar *ecode;
     91  const uschar* ecode;
    8992  int offset_top;
    9093  eptrblock *eptrb;
     
    266269
    267270#define RMATCH_WHERE(num) &&RRETURN_##num
    268 #define RRETURN_LABEL *stack.currentFrame->where
     271#define RRETURN_LABEL *stack.currentFrame->returnLocation
    269272
    270273#endif
     
    272275#define RMATCH(num, ra, rb, rc)\
    273276  {\
    274   if (stack.currentFrame >= stack.frames && stack.currentFrame + 1 < stack.framesEnd)\
    275     newframe = stack.currentFrame + 1;\
    276   else\
    277     newframe = new matchframe;\
    278   newframe->eptr = stack.currentFrame->eptr;\
    279   newframe->ecode = (ra);\
    280   newframe->offset_top = stack.currentFrame->offset_top;\
    281   newframe->eptrb = (rb);\
    282   is_group_start = (rc);\
    283   ++rdepth;\
    284   newframe->prevframe = stack.currentFrame;\
    285   stack.currentFrame = newframe;\
    286   stack.currentFrame->where = RMATCH_WHERE(num);\
    287   DPRINTF(("restarting from line %d\n", __LINE__));\
    288   goto RECURSE;\
     277    stack.pushNewFrame((ra), (rb), RMATCH_WHERE(num)); \
     278    is_group_start = (rc);\
     279    ++rdepth;\
     280    DPRINTF(("restarting from line %d\n", __LINE__));\
     281    goto RECURSE;\
    289282RRETURN_##num:\
    290   newframe = stack.currentFrame;\
    291   stack.currentFrame = stack.currentFrame->prevframe;\
    292   if (!(newframe >= stack.frames && newframe < stack.framesEnd))\
    293     delete newframe;\
    294   --rdepth;\
    295   DPRINTF(("did a goto back to line %d\n", __LINE__));\
     283    stack.popCurrentFrame(); \
     284    --rdepth;\
     285    DPRINTF(("did a goto back to line %d\n", __LINE__));\
    296286  }
    297287 
     
    303293    RRETURN;\
    304294  }
    305 
    306 #define RRETURN_ERROR(error) \
    307     return matchError(error, stack);
    308295
    309296/*************************************************
     
    336323        currentFrame = frames;
    337324    }
     325   
     326    /* The value 16 here is large enough that most regular expressions don't require
     327     any calls to pcre_stack_malloc, yet the amount of stack used for the array is
     328     modest enough that we don't run out of stack. */
    338329    matchframe frames[16];
    339330    matchframe* framesEnd;
    340331    matchframe* currentFrame;
     332   
     333    inline bool canUseStackBufferForNextFrame()
     334    {
     335        return (currentFrame >= frames && currentFrame + 1 < framesEnd);
     336    }
     337   
     338    inline matchframe* allocateNextFrame()
     339    {
     340        if (canUseStackBufferForNextFrame())
     341            return currentFrame + 1;
     342        return new matchframe;
     343    }
     344   
     345    inline void pushNewFrame(const uschar* ecode, eptrblock* eptrb, ReturnLocation returnLocation)
     346    {
     347        matchframe* newframe = allocateNextFrame();
     348        newframe->prevframe = currentFrame;
     349
     350        newframe->eptr = currentFrame->eptr;
     351        newframe->offset_top = currentFrame->offset_top;
     352        newframe->ecode = ecode;
     353        newframe->eptrb = eptrb;
     354        newframe->returnLocation = returnLocation;
     355
     356        currentFrame = newframe;
     357    }
     358   
     359    inline bool frameIsStackAllocated(matchframe* frame)
     360    {
     361        return (frame >= frames && frame < framesEnd);
     362    }
     363   
     364    inline void popCurrentFrame()
     365    {
     366        matchframe* oldFrame = currentFrame;
     367        currentFrame = currentFrame->prevframe;
     368        if (!frameIsStackAllocated(oldFrame))
     369            delete oldFrame;
     370    }
    341371
    342372    void unrollAnyHeapAllocatedFrames()
    343373    {
    344         while (!(currentFrame >= frames && currentFrame < framesEnd)) {
    345             matchframe* parentFrame = currentFrame->prevframe;
    346             delete currentFrame;
    347             currentFrame = parentFrame;
     374        while (!frameIsStackAllocated(currentFrame)) {
     375            matchframe* oldFrame = currentFrame;
     376            currentFrame = currentFrame->prevframe;
     377            delete oldFrame;
    348378        }
    349379    }
     
    370400    BOOL minimize = false; /* Initialization not really needed, but some compilers think so. */
    371401   
    372     /* The value 16 here is large enough that most regular expressions don't require
    373      any calls to pcre_stack_malloc, yet the amount of stack used for the array is
    374      modest enough that we don't run out of stack. */
    375402    MatchStack stack;
    376     matchframe* newframe;
    377    
     403
    378404    /* The opcode jump table. */
    379405#ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
     
    391417   
    392418#ifdef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION
    393     stack.currentFrame->where = &&RETURN;
     419    stack.currentFrame->returnLocation = &&RETURN;
    394420#else
    395     stack.currentFrame->where = 0;
     421    stack.currentFrame->returnLocation = 0;
    396422#endif
    397423   
     
    417443   
    418444    if (md->match_call_count++ >= MATCH_LIMIT)
    419         RRETURN_ERROR(JSRegExpErrorMatchLimit);
     445        return matchError(JSRegExpErrorMatchLimit, stack);
    420446    if (rdepth >= MATCH_LIMIT_RECURSION)
    421         RRETURN_ERROR(JSRegExpErrorRecursionLimit);
     447        return matchError(JSRegExpErrorRecursionLimit, stack);
    422448   
    423449    /* At the start of a bracketed group, add the current subject pointer to the
     
    490516                do {
    491517                    RMATCH(6, stack.currentFrame->ecode + 1 + LINK_SIZE, NULL, match_isgroup);
    492                     if (is_match) break;
     518                    if (is_match)
     519                        break;
    493520                    stack.currentFrame->ecode += GET(stack.currentFrame->ecode, 1);
    494521                } while (*stack.currentFrame->ecode == OP_ALT);
     
    16641691                            default:
    16651692                            ASSERT_NOT_REACHED();
    1666                             RRETURN_ERROR(JSRegExpErrorInternal);
     1693                            return matchError(JSRegExpErrorInternal, stack);
    16671694                    }  /* End switch(stack.currentFrame->ctype) */
    16681695                }
     
    17231750                        default:
    17241751                            ASSERT_NOT_REACHED();
    1725                             RRETURN_ERROR(JSRegExpErrorInternal);
     1752                            return matchError(JSRegExpErrorInternal, stack);
    17261753                        }
    17271754                    }
     
    18381865                            default:
    18391866                            ASSERT_NOT_REACHED();
    1840                             RRETURN_ERROR(JSRegExpErrorInternal);
     1867                            return matchError(JSRegExpErrorInternal, stack);
    18411868                    }
    18421869                   
     
    18671894                BEGIN_OPCODE(CRSTAR):
    18681895                ASSERT_NOT_REACHED();
    1869                 RRETURN_ERROR(JSRegExpErrorInternal);
     1896                return matchError(JSRegExpErrorInternal, stack);
    18701897               
    18711898#ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP
     
    19441971   
    19451972RRETURN_SWITCH:
    1946     switch (stack.currentFrame->where)
     1973    switch (stack.currentFrame->returnLocation)
    19471974    {
    19481975        case 0: goto RETURN;
     
    19802007    }
    19812008   
    1982     abort();
    1983     RRETURN_ERROR(JSRegExpErrorInternal);
     2009    ASSERT_NOT_REACHED();
     2010    return matchError(JSRegExpErrorInternal, stack);
    19842011   
    19852012#endif
Note: See TracChangeset for help on using the changeset viewer.