Changeset 28164 in webkit
- Timestamp:
- Nov 29, 2007, 3:25:16 AM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r28163 r28164 20 20 (MatchStack::pushNewFrame): 21 21 (match): 22 23 2007-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: 22 38 23 39 2007-11-24 Eric Seidel <eric@webkit.org> -
trunk/JavaScriptCore/pcre/pcre_exec.cpp
r28163 r28164 125 125 126 126 struct MatchData { 127 unsigned long int match_call_count;128 127 int* offset_vector; /* Offset vector */ 129 128 int offset_end; /* One past the end */ … … 285 284 stack.pushNewFrame((ra), (rb), RMATCH_WHERE(num)); \ 286 285 is_group_start = (rc);\ 287 ++rdepth;\ 286 if (stack.size >= MATCH_LIMIT_RECURSION) \ 287 return matchError(JSRegExpErrorRecursionLimit, stack); \ 288 288 DPRINTF(("restarting from line %d\n", __LINE__));\ 289 289 goto RECURSE;\ 290 290 RRETURN_##num:\ 291 291 stack.popCurrentFrame(); \ 292 --rdepth;\293 292 DPRINTF(("did a goto back to line %d\n", __LINE__));\ 294 293 } … … 330 329 framesEnd = frames + sizeof(frames) / sizeof(frames[0]); 331 330 currentFrame = frames; 331 size = 0; 332 332 } 333 333 … … 338 338 MatchFrame* framesEnd; 339 339 MatchFrame* currentFrame; 340 unsigned size; 340 341 341 342 inline bool canUseStackBufferForNextFrame() … … 361 362 newframe->args.eptrb = eptrb; 362 363 newframe->returnLocation = returnLocation; 364 size++; 363 365 364 366 currentFrame = newframe; … … 376 378 if (!frameIsStackAllocated(oldFrame)) 377 379 delete oldFrame; 380 size--; 378 381 } 379 382 380 void unrollAnyHeapAllocatedFrames()383 void popAllFrames() 381 384 { 382 while (!frameIsStackAllocated(currentFrame)) { 383 MatchFrame* oldFrame = currentFrame; 384 currentFrame = currentFrame->previousFrame; 385 delete oldFrame; 386 } 385 while (size) 386 popCurrentFrame(); 387 387 } 388 388 }; … … 390 390 static int matchError(int errorCode, MatchStack& stack) 391 391 { 392 stack. unrollAnyHeapAllocatedFrames();392 stack.popAllFrames(); 393 393 return errorCode; 394 394 } … … 418 418 int c; 419 419 420 unsigned rdepth = 0;421 422 420 bool cur_is_word; 423 421 bool prev_is_word; … … 464 462 complicated macro. It has to be used in one particular way. This shouldn't, 465 463 however, impact performance when true recursion is being used. */ 466 467 /* First check that we haven't called match() too many times, or that we468 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);474 464 475 465 /* At the start of a bracketed group, add the current subject pointer to the … … 2266 2256 if certain parts of the pattern were not used. */ 2267 2257 2268 match_block.match_call_count = 0;2269 2270 2271 2258 /* The code starts after the JSRegExp block and the capture name table. */ 2272 2259 const uschar* start_code = (const uschar*)(re + 1); -
trunk/JavaScriptCore/pcre/pcre_internal.h
r28163 r28164 86 86 #define LINK_SIZE 2 87 87 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 89 limit the maximum amount of stack (or heap, if NO_RECURSE is defined) that is used. The 90 value of MATCH_LIMIT_RECURSION applies only to recursive calls of match(). */ 91 92 #define MATCH_LIMIT_RECURSION 10000000 108 93 109 94 #define _pcre_default_tables kjs_pcre_default_tables
Note:
See TracChangeset
for help on using the changeset viewer.