Bug 22303 - Optimize /^x/ regexps to fail fast
Summary: Optimize /^x/ regexps to fail fast
Status: RESOLVED WORKSFORME
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Geoffrey Garen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-16 21:27 PST by Geoffrey Garen
Modified: 2011-07-05 14:26 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2008-11-16 21:27:37 PST
See bug 18086 -- let's do that optimization in WREC.

Here's what I think can be a layout test:

// Check that an initial ^ will result in a faster match fail.
var s = "a";
var i;

for (i = 0; i < 20; i++)
  s = s + s;

function test(string, regexp)
{
    var start = new Date;
    for (i = 0; i < 100; i++)
        regexp.test(s);
    return new Date - start;
}

var result1 = test(s, /b/);
var result2 = test(s, /^b/);

alert(result1);
alert(result2);

if ((result1 - result2) / result1 > .75)
    testPassed("Congrats, your browser didn't hang!");

testFailed("/^b/ did not discover a match failure faster than /b/");

var successfullyParsed = true;
Comment 1 Gavin Barraclough 2011-07-05 14:26:01 PDT
This optimization now exists in YARR.