Changeset 27830 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 15, 2007, 4:17:54 PM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r27829 r27830 3 3 Reviewed by Sam. 4 4 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 18 2007-11-15 Eric Seidel <[email protected]> 19 20 Reviewed by Sam. 21 5 22 Remove RETURN_ERROR, add MatchStack 6 23 7 24 * pcre/pcre_exec.cpp: 8 25 (MatchStack::MatchStack): … … 10 27 (matchError): 11 28 (match): 12 29 13 30 2007-11-15 Eric Seidel <[email protected]> 14 31 -
trunk/JavaScriptCore/pcre/pcre_exec.cpp
r27829 r27830 73 73 /* Structure for remembering the local variables in a private frame */ 74 74 75 76 77 #ifndef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION 78 typedef int ReturnLocation; 79 #else 80 typedef void* ReturnLocation; 81 #endif 82 75 83 typedef 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; 84 87 85 88 /* Function arguments that may change */ 86 89 87 90 const pcre_uchar *eptr; 88 const uschar *ecode;91 const uschar* ecode; 89 92 int offset_top; 90 93 eptrblock *eptrb; … … 266 269 267 270 #define RMATCH_WHERE(num) &&RRETURN_##num 268 #define RRETURN_LABEL *stack.currentFrame-> where271 #define RRETURN_LABEL *stack.currentFrame->returnLocation 269 272 270 273 #endif … … 272 275 #define RMATCH(num, ra, rb, rc)\ 273 276 {\ 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;\ 289 282 RRETURN_##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__));\ 296 286 } 297 287 … … 303 293 RRETURN;\ 304 294 } 305 306 #define RRETURN_ERROR(error) \307 return matchError(error, stack);308 295 309 296 /************************************************* … … 336 323 currentFrame = frames; 337 324 } 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. */ 338 329 matchframe frames[16]; 339 330 matchframe* framesEnd; 340 331 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 } 341 371 342 372 void unrollAnyHeapAllocatedFrames() 343 373 { 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; 348 378 } 349 379 } … … 370 400 BOOL minimize = false; /* Initialization not really needed, but some compilers think so. */ 371 401 372 /* The value 16 here is large enough that most regular expressions don't require373 any calls to pcre_stack_malloc, yet the amount of stack used for the array is374 modest enough that we don't run out of stack. */375 402 MatchStack stack; 376 matchframe* newframe; 377 403 378 404 /* The opcode jump table. */ 379 405 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP … … 391 417 392 418 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_RECURSION 393 stack.currentFrame-> where= &&RETURN;419 stack.currentFrame->returnLocation = &&RETURN; 394 420 #else 395 stack.currentFrame-> where= 0;421 stack.currentFrame->returnLocation = 0; 396 422 #endif 397 423 … … 417 443 418 444 if (md->match_call_count++ >= MATCH_LIMIT) 419 RRETURN_ERROR(JSRegExpErrorMatchLimit);445 return matchError(JSRegExpErrorMatchLimit, stack); 420 446 if (rdepth >= MATCH_LIMIT_RECURSION) 421 RRETURN_ERROR(JSRegExpErrorRecursionLimit);447 return matchError(JSRegExpErrorRecursionLimit, stack); 422 448 423 449 /* At the start of a bracketed group, add the current subject pointer to the … … 490 516 do { 491 517 RMATCH(6, stack.currentFrame->ecode + 1 + LINK_SIZE, NULL, match_isgroup); 492 if (is_match) break; 518 if (is_match) 519 break; 493 520 stack.currentFrame->ecode += GET(stack.currentFrame->ecode, 1); 494 521 } while (*stack.currentFrame->ecode == OP_ALT); … … 1664 1691 default: 1665 1692 ASSERT_NOT_REACHED(); 1666 RRETURN_ERROR(JSRegExpErrorInternal);1693 return matchError(JSRegExpErrorInternal, stack); 1667 1694 } /* End switch(stack.currentFrame->ctype) */ 1668 1695 } … … 1723 1750 default: 1724 1751 ASSERT_NOT_REACHED(); 1725 RRETURN_ERROR(JSRegExpErrorInternal);1752 return matchError(JSRegExpErrorInternal, stack); 1726 1753 } 1727 1754 } … … 1838 1865 default: 1839 1866 ASSERT_NOT_REACHED(); 1840 RRETURN_ERROR(JSRegExpErrorInternal);1867 return matchError(JSRegExpErrorInternal, stack); 1841 1868 } 1842 1869 … … 1867 1894 BEGIN_OPCODE(CRSTAR): 1868 1895 ASSERT_NOT_REACHED(); 1869 RRETURN_ERROR(JSRegExpErrorInternal);1896 return matchError(JSRegExpErrorInternal, stack); 1870 1897 1871 1898 #ifdef USE_COMPUTED_GOTO_FOR_MATCH_OPCODE_LOOP … … 1944 1971 1945 1972 RRETURN_SWITCH: 1946 switch (stack.currentFrame-> where)1973 switch (stack.currentFrame->returnLocation) 1947 1974 { 1948 1975 case 0: goto RETURN; … … 1980 2007 } 1981 2008 1982 abort();1983 RRETURN_ERROR(JSRegExpErrorInternal);2009 ASSERT_NOT_REACHED(); 2010 return matchError(JSRegExpErrorInternal, stack); 1984 2011 1985 2012 #endif
Note:
See TracChangeset
for help on using the changeset viewer.