Ignore:
Timestamp:
Nov 29, 2007, 3:05:07 AM (18 years ago)
Author:
[email protected]
Message:

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

Reviewed by Maciej.

Remove register keyword and more cleanup

  • pcre/pcre_compile.cpp: (find_fixedlength): (compile_branch): (is_anchored): (is_startline): (find_firstassertedchar): (calculateCompiledPatternLengthAndFlags): (jsRegExpCompile):
  • pcre/pcre_exec.cpp: (MatchStack::canUseStackBufferForNextFrame): (MatchStack::allocateNextFrame): (MatchStack::pushNewFrame): (MatchStack::frameIsStackAllocated): (MatchStack::popCurrentFrame): (MatchStack::unrollAnyHeapAllocatedFrames): (getUTF8CharAndIncrementLength): (match): (jsRegExpExecute):
  • pcre/pcre_internal.h: (PUT2INC): (isLeadingSurrogate): (isTrailingSurrogate): (decodeSurrogatePair): (getChar):
  • pcre/pcre_ord2utf8.cpp: (_pcre_ord2utf8):
  • pcre/pcre_xclass.cpp: (getUTF8CharAndAdvancePointer): (_pcre_xclass):
File:
1 edited

Legend:

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

    r28138 r28139  
    8181#endif
    8282
    83 typedef struct matchframe {
     83struct MatchFrame {
    8484  ReturnLocation returnLocation;
    8585
    86   struct matchframe* prevframe;
     86  struct MatchFrame* previousFrame;
    8787
    8888  /* Function arguments that may change */
    8989
    90   const pcre_uchar *eptr;
     90  const pcre_uchar* eptr;
    9191  const uschar* ecode;
    9292  int offset_top;
    93   eptrblock *eptrb;
     93  eptrblock* eptrb;
    9494
    9595  /* Function local variables */
    9696
    97   const uschar *data;
    98   const uschar *next;
    99   const pcre_uchar *pp;
    100   const uschar *prev;
    101   const pcre_uchar *saved_eptr;
     97  const uschar* data;
     98  const uschar* next;
     99  const pcre_uchar* pp;
     100  const uschar* prev;
     101  const pcre_uchar* saved_eptr;
    102102
    103103  int repeat_othercase;
     
    113113
    114114  eptrblock newptrb;
    115 } matchframe;
     115};
    116116
    117117/* Structure for passing "static" information around between the functions
     
    197197
    198198static BOOL
    199 match_ref(int offset, register USPTR eptr, int length, match_data *md)
     199match_ref(int offset, USPTR eptr, int length, match_data *md)
    200200{
    201201USPTR p = md->start_subject + md->offset_vector[offset];
     
    327327     any calls to pcre_stack_malloc, yet the amount of stack used for the array is
    328328     modest enough that we don't run out of stack. */
    329     matchframe frames[16];
    330     matchframe* framesEnd;
    331     matchframe* currentFrame;
     329    MatchFrame frames[16];
     330    MatchFrame* framesEnd;
     331    MatchFrame* currentFrame;
    332332   
    333333    inline bool canUseStackBufferForNextFrame()
     
    336336    }
    337337   
    338     inline matchframe* allocateNextFrame()
     338    inline MatchFrame* allocateNextFrame()
    339339    {
    340340        if (canUseStackBufferForNextFrame())
    341341            return currentFrame + 1;
    342         return new matchframe;
     342        return new MatchFrame;
    343343    }
    344344   
    345345    inline void pushNewFrame(const uschar* ecode, eptrblock* eptrb, ReturnLocation returnLocation)
    346346    {
    347         matchframe* newframe = allocateNextFrame();
    348         newframe->prevframe = currentFrame;
     347        MatchFrame* newframe = allocateNextFrame();
     348        newframe->previousFrame = currentFrame;
    349349
    350350        newframe->eptr = currentFrame->eptr;
     
    357357    }
    358358   
    359     inline bool frameIsStackAllocated(matchframe* frame)
     359    inline bool frameIsStackAllocated(MatchFrame* frame)
    360360    {
    361361        return (frame >= frames && frame < framesEnd);
     
    364364    inline void popCurrentFrame()
    365365    {
    366         matchframe* oldFrame = currentFrame;
    367         currentFrame = currentFrame->prevframe;
     366        MatchFrame* oldFrame = currentFrame;
     367        currentFrame = currentFrame->previousFrame;
    368368        if (!frameIsStackAllocated(oldFrame))
    369369            delete oldFrame;
     
    373373    {
    374374        while (!frameIsStackAllocated(currentFrame)) {
    375             matchframe* oldFrame = currentFrame;
    376             currentFrame = currentFrame->prevframe;
     375            MatchFrame* oldFrame = currentFrame;
     376            currentFrame = currentFrame->previousFrame;
    377377            delete oldFrame;
    378378        }
     
    386386}
    387387
     388/* Get the next UTF-8 character, not advancing the pointer, incrementing length
     389 if there are extra bytes. This is called when we know we are in UTF-8 mode. */
     390
     391static inline void getUTF8CharAndIncrementLength(int& c, const uschar* eptr, int& len)
     392{
     393    c = *eptr;
     394    if ((c & 0xc0) == 0xc0) {
     395        int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */
     396        int gcss = 6 * gcaa;
     397        c = (c & _pcre_utf8_table3[gcaa]) << gcss;
     398        for (int gcii = 1; gcii <= gcaa; gcii++) {
     399            gcss -= 6;
     400            c |= (eptr[gcii] & 0x3f) << gcss;
     401        }
     402        len += gcaa;
     403    }
     404}
     405
    388406static int match(USPTR eptr, const uschar* ecode, int offset_top, match_data* md)
    389407{
    390     register int is_match = false;
    391     register int i;
    392     register int c;
     408    int is_match = false;
     409    int i;
     410    int c;
    393411   
    394412    unsigned rdepth = 0;
     
    759777                else {
    760778                    const pcre_uchar *lastptr = stack.currentFrame->eptr - 1;
    761                     while(ISMIDCHAR(*lastptr))
     779                    while(isTrailingSurrogate(*lastptr))
    762780                        lastptr--;
    763                     GETCHAR(c, lastptr);
     781                    getChar(c, lastptr);
    764782                    prev_is_word = c < 128 && (md->ctypes[c] & ctype_word) != 0;
    765783                }
     
    767785                    cur_is_word = false;
    768786                else {
    769                     GETCHAR(c, stack.currentFrame->eptr);
     787                    getChar(c, stack.currentFrame->eptr);
    770788                    cur_is_word = c < 128 && (md->ctypes[c] & ctype_word) != 0;
    771789                }
     
    784802                if (stack.currentFrame->eptr++ >= md->end_subject)
    785803                    RRETURN_NO_MATCH;
    786                 while (stack.currentFrame->eptr < md->end_subject && ISMIDCHAR(*stack.currentFrame->eptr))
     804                while (stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr))
    787805                    stack.currentFrame->eptr++;
    788806                stack.currentFrame->ecode++;
     
    11721190                stack.currentFrame->length = 1;
    11731191                stack.currentFrame->ecode++;
    1174                 GETUTF8CHARLEN(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
     1192                getUTF8CharAndIncrementLength(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
    11751193            {
    11761194                int dc;
     
    11811199                case 1:
    11821200                    dc = *stack.currentFrame->eptr++;
    1183                     if (IS_LEADING_SURROGATE(dc))
     1201                    if (isLeadingSurrogate(dc))
    11841202                        RRETURN_NO_MATCH;
    11851203                    break;
     
    11971215                stack.currentFrame->length = 1;
    11981216                stack.currentFrame->ecode++;
    1199                 GETUTF8CHARLEN(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
     1217                getUTF8CharAndIncrementLength(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
    12001218               
    12011219                if (md->end_subject - stack.currentFrame->eptr == 0)
     
    12061224                if (md->end_subject - stack.currentFrame->eptr == 1) {
    12071225                    dc = *stack.currentFrame->eptr++;
    1208                     if (IS_LEADING_SURROGATE(dc))
     1226                    if (isLeadingSurrogate(dc))
    12091227                        RRETURN_NO_MATCH;
    12101228                } else
     
    12801298               
    12811299                stack.currentFrame->length = 1;
    1282                 GETUTF8CHARLEN(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
     1300                getUTF8CharAndIncrementLength(stack.currentFrame->fc, stack.currentFrame->ecode, stack.currentFrame->length);
    12831301                if (min * (stack.currentFrame->fc > 0xFFFF ? 2 : 1) > md->end_subject - stack.currentFrame->eptr)
    12841302                    RRETURN_NO_MATCH;
     
    13331351                    for (i = 1; i <= min; i++) {
    13341352                        int nc;
    1335                         GETCHAR(nc, stack.currentFrame->eptr);
     1353                        getChar(nc, stack.currentFrame->eptr);
    13361354                        if (nc != stack.currentFrame->fc)
    13371355                            RRETURN_NO_MATCH;
     
    13501368                            if (stack.currentFrame->fi >= stack.currentFrame->max || stack.currentFrame->eptr >= md->end_subject)
    13511369                                RRETURN;
    1352                             GETCHAR(nc, stack.currentFrame->eptr);
     1370                            getChar(nc, stack.currentFrame->eptr);
    13531371                            if (*stack.currentFrame->eptr != stack.currentFrame->fc)
    13541372                                RRETURN;
     
    13621380                            if (stack.currentFrame->eptr > md->end_subject - 2)
    13631381                                break;
    1364                             GETCHAR(nc, stack.currentFrame->eptr);
     1382                            getChar(nc, stack.currentFrame->eptr);
    13651383                            if (*stack.currentFrame->eptr != stack.currentFrame->fc)
    13661384                                break;
     
    14551473                   
    14561474                    {
    1457                         register int d;
     1475                        int d;
    14581476                        for (i = 1; i <= min; i++) {
    14591477                            GETCHARINC(d, stack.currentFrame->eptr);
     
    14691487                   
    14701488                    if (minimize) {
    1471                         register int d;
     1489                        int d;
    14721490                        for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
    14731491                            RMATCH(38, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
     
    14891507                       
    14901508                        {
    1491                             register int d;
     1509                            int d;
    14921510                            for (i = min; i < stack.currentFrame->max; i++) {
    14931511                                int len = 1;
     
    15201538                else {
    15211539                    {
    1522                         register int d;
     1540                        int d;
    15231541                        for (i = 1; i <= min; i++) {
    15241542                            GETCHARINC(d, stack.currentFrame->eptr);
     
    15321550                   
    15331551                    if (minimize) {
    1534                         register int d;
     1552                        int d;
    15351553                        for (stack.currentFrame->fi = min;; stack.currentFrame->fi++) {
    15361554                            RMATCH(42, stack.currentFrame->ecode, stack.currentFrame->eptrb, 0);
     
    15501568                       
    15511569                        {
    1552                             register int d;
     1570                            int d;
    15531571                            for (i = min; i < stack.currentFrame->max; i++) {
    15541572                                int len = 1;
     
    16301648                                    RRETURN_NO_MATCH;
    16311649                                ++stack.currentFrame->eptr;
    1632                                 while (stack.currentFrame->eptr < md->end_subject && ISMIDCHAR(*stack.currentFrame->eptr))
     1650                                while (stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr))
    16331651                                    stack.currentFrame->eptr++;
    16341652                            }
     
    16581676                                    (*stack.currentFrame->eptr < 128 && (md->ctypes[*stack.currentFrame->eptr] & ctype_space) != 0))
    16591677                                    RRETURN_NO_MATCH;
    1660                                 while (++stack.currentFrame->eptr < md->end_subject && ISMIDCHAR(*stack.currentFrame->eptr)) { }
     1678                                while (++stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr)) { }
    16611679                            }
    16621680                            break;
     
    16761694                                    (*stack.currentFrame->eptr < 128 && (md->ctypes[*stack.currentFrame->eptr] & ctype_word) != 0))
    16771695                                    RRETURN_NO_MATCH;
    1678                                 while (++stack.currentFrame->eptr < md->end_subject && ISMIDCHAR(*stack.currentFrame->eptr)) { }
     1696                                while (++stack.currentFrame->eptr < md->end_subject && isTrailingSurrogate(*stack.currentFrame->eptr)) { }
    16791697                            }
    16801698                            break;
     
    21322150    USPTR start_match = (USPTR)subject + start_offset;
    21332151    USPTR req_byte_ptr = start_match - 1;
     2152    bool startline = re->options & PCRE_STARTLINE;
    21342153   
    21352154    do {
     
    21382157        /* Reset the maximum number of extractions we might see. */
    21392158       
    2140         if (match_block.offset_vector != NULL) {
     2159        if (match_block.offset_vector) {
    21412160            int* iptr = match_block.offset_vector;
    21422161            int* iend = iptr + resetcount;
     
    21712190        /* Or to just after \n for a multiline match if possible */
    21722191       
    2173         else if (re->options & PCRE_STARTLINE) {
     2192        else if (startline) {
    21742193            if (start_match > match_block.start_subject + start_offset) {
    21752194                while (start_match < end_subject && !isNewline(start_match[-1]))
     
    22652284        if (returnCode == MATCH_NOMATCH) {
    22662285            start_match++;
    2267             while(start_match < end_subject && ISMIDCHAR(*start_match))
     2286            while(start_match < end_subject && isTrailingSurrogate(*start_match))
    22682287                start_match++;
    22692288            continue;
Note: See TracChangeset for help on using the changeset viewer.