Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | // The Great Computer Language Shootout |
michael@0 | 2 | // http://shootout.alioth.debian.org |
michael@0 | 3 | // |
michael@0 | 4 | // Contributed by Ian Osgood |
michael@0 | 5 | |
michael@0 | 6 | var last = 42, A = 3877, C = 29573, M = 139968; |
michael@0 | 7 | |
michael@0 | 8 | function rand(max) { |
michael@0 | 9 | last = (last * A + C) % M; |
michael@0 | 10 | return max * last / M; |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | var ALU = |
michael@0 | 14 | "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" + |
michael@0 | 15 | "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" + |
michael@0 | 16 | "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" + |
michael@0 | 17 | "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" + |
michael@0 | 18 | "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" + |
michael@0 | 19 | "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" + |
michael@0 | 20 | "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; |
michael@0 | 21 | |
michael@0 | 22 | var IUB = { |
michael@0 | 23 | a:0.27, c:0.12, g:0.12, t:0.27, |
michael@0 | 24 | B:0.02, D:0.02, H:0.02, K:0.02, |
michael@0 | 25 | M:0.02, N:0.02, R:0.02, S:0.02, |
michael@0 | 26 | V:0.02, W:0.02, Y:0.02 |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | var HomoSap = { |
michael@0 | 30 | a: 0.3029549426680, |
michael@0 | 31 | c: 0.1979883004921, |
michael@0 | 32 | g: 0.1975473066391, |
michael@0 | 33 | t: 0.3015094502008 |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function makeCumulative(table) { |
michael@0 | 37 | var last = null; |
michael@0 | 38 | /* BEGIN LOOP */ |
michael@0 | 39 | for (var c in table) { |
michael@0 | 40 | if (last) table[c] += table[last]; |
michael@0 | 41 | last = c; |
michael@0 | 42 | } |
michael@0 | 43 | /* END LOOP */ |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function fastaRepeat(n, seq) { |
michael@0 | 47 | var seqi = 0, lenOut = 60; |
michael@0 | 48 | /* BEGIN LOOP */ |
michael@0 | 49 | while (n>0) { |
michael@0 | 50 | if (n<lenOut) lenOut = n; |
michael@0 | 51 | if (seqi + lenOut < seq.length) { |
michael@0 | 52 | ret = seq.substring(seqi, seqi+lenOut); |
michael@0 | 53 | seqi += lenOut; |
michael@0 | 54 | } else { |
michael@0 | 55 | var s = seq.substring(seqi); |
michael@0 | 56 | seqi = lenOut - s.length; |
michael@0 | 57 | ret = s + seq.substring(0, seqi); |
michael@0 | 58 | } |
michael@0 | 59 | n -= lenOut; |
michael@0 | 60 | } |
michael@0 | 61 | /* END LOOP */ |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function fastaRandom(n, table) { |
michael@0 | 65 | var line = new Array(60); |
michael@0 | 66 | makeCumulative(table); |
michael@0 | 67 | /* BEGIN LOOP */ |
michael@0 | 68 | while (n>0) { |
michael@0 | 69 | if (n<line.length) line = new Array(n); |
michael@0 | 70 | /* BEGIN LOOP */ |
michael@0 | 71 | for (var i=0; i<line.length; i++) { |
michael@0 | 72 | var r = rand(1); |
michael@0 | 73 | /* BEGIN LOOP */ |
michael@0 | 74 | for (var c in table) { |
michael@0 | 75 | if (r < table[c]) { |
michael@0 | 76 | line[i] = c; |
michael@0 | 77 | break; |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | /* END LOOP */ |
michael@0 | 81 | } |
michael@0 | 82 | /* END LOOP */ |
michael@0 | 83 | ret = line.join(''); |
michael@0 | 84 | n -= line.length; |
michael@0 | 85 | } |
michael@0 | 86 | /* END LOOP */ |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | var ret; |
michael@0 | 90 | |
michael@0 | 91 | var count = 7; |
michael@0 | 92 | ret = fastaRepeat(2*count*100000, ALU); |
michael@0 | 93 | ret = fastaRandom(3*count*1000, IUB); |
michael@0 | 94 | ret = fastaRandom(5*count*1000, HomoSap); |
michael@0 | 95 |