js/src/devtools/jint/sunspider/access-binary-trees.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.

michael@0 1 /* The Great Computer Language Shootout
michael@0 2 http://shootout.alioth.debian.org/
michael@0 3 contributed by Isaac Gouy */
michael@0 4
michael@0 5 function TreeNode(left,right,item){
michael@0 6 this.left = left;
michael@0 7 this.right = right;
michael@0 8 this.item = item;
michael@0 9 }
michael@0 10
michael@0 11 TreeNode.prototype.itemCheck = function(){
michael@0 12 if (this.left==null) return this.item;
michael@0 13 else return this.item + this.left.itemCheck() - this.right.itemCheck();
michael@0 14 }
michael@0 15
michael@0 16 function bottomUpTree(item,depth){
michael@0 17 if (depth>0){
michael@0 18 return new TreeNode(
michael@0 19 bottomUpTree(2*item-1, depth-1)
michael@0 20 ,bottomUpTree(2*item, depth-1)
michael@0 21 ,item
michael@0 22 );
michael@0 23 }
michael@0 24 else {
michael@0 25 return new TreeNode(null,null,item);
michael@0 26 }
michael@0 27 }
michael@0 28
michael@0 29 var ret;
michael@0 30
michael@0 31 /* BEGIN LOOP */
michael@0 32 for ( var n = 4; n <= 7; n += 1 ) {
michael@0 33 var minDepth = 4;
michael@0 34 var maxDepth = Math.max(minDepth + 2, n);
michael@0 35 var stretchDepth = maxDepth + 1;
michael@0 36
michael@0 37 var check = bottomUpTree(0,stretchDepth).itemCheck();
michael@0 38
michael@0 39 var longLivedTree = bottomUpTree(0,maxDepth);
michael@0 40 /* BEGIN LOOP */
michael@0 41 for (var depth=minDepth; depth<=maxDepth; depth+=2){
michael@0 42 var iterations = 1 << (maxDepth - depth + minDepth);
michael@0 43
michael@0 44 check = 0;
michael@0 45 /* BEGIN LOOP */
michael@0 46 for (var i=1; i<=iterations; i++){
michael@0 47 check += bottomUpTree(i,depth).itemCheck();
michael@0 48 check += bottomUpTree(-i,depth).itemCheck();
michael@0 49 }
michael@0 50 /* END LOOP */
michael@0 51 }
michael@0 52 /* END LOOP */
michael@0 53
michael@0 54 ret = longLivedTree.itemCheck();
michael@0 55 }
michael@0 56 /* END LOOP */

mercurial