js/src/devtools/jint/sunspider/access-nsieve.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 // The Great Computer Language Shootout
     2 // http://shootout.alioth.debian.org/
     3 //
     4 // modified by Isaac Gouy
     6 function pad(number,width){
     7    var s = number.toString();
     8    var prefixWidth = width - s.length;
     9    if (prefixWidth>0){
    10       /* BEGIN LOOP */
    11       for (var i=1; i<=prefixWidth; i++) s = " " + s;
    12       /* END LOOP */
    13    }
    14    return s;
    15 }
    17 function nsieve(m, isPrime){
    18    var i, k, count;
    20    /* BEGIN LOOP */
    21    for (i=2; i<=m; i++) { isPrime[i] = true; }
    22    /* END LOOP */
    23    count = 0;
    25    /* BEGIN LOOP */
    26    for (i=2; i<=m; i++){
    27       if (isPrime[i]) {
    28 	 /* BEGIN LOOP */
    29          for (k=i+i; k<=m; k+=i) isPrime[k] = false;
    30 	 /* END LOOP */
    31          count++;
    32       }
    33    }
    34    /* END LOOP */
    35    return count;
    36 }
    38 function sieve() {
    39     /* BEGIN LOOP */
    40     for (var i = 1; i <= 3; i++ ) {
    41         var m = (1<<i)*10000;
    42         var flags = Array(m+1);
    43         nsieve(m, flags);
    44     }
    45     /* END LOOP */
    46 }
    48 sieve();

mercurial