Optimizations
|
|
This thread is only for optimizations
|
|
|
You can shorten and simply the code by creating arrays like You do this: this.textContent="Hide Ultimate Options"; but sometimes the value of this changes as stated by mozilla. You should use E.currentTarget instead of this.
|
|
|
I switched from literal array notation because I tested it and it was actually slower.
var fns = new Array (
function() {
return [1, 2, 3, 4];
},
function() {
return new Array(1, 2, 3, 4);
}
), res=new Array();
for(var f = 0; f < fns.length; f++) {
var st = new Date();
for(var i=10000; i>=0; --i)
fns[f]();
res.push("#" + f + ":\t" + (new Date() - st));
}
res.join("\n");
Unless I did something wrong. I can't imagine why this is the case. |
|
|
Hmm you're right... it's 1.2 times faster with |
|
|
Optimized create() code a bit...
// Create by avg, modified by JoeSimmons
function create(a,b) {
var ret=document.createElement(a);
if(b) for(var prop in b) {
if(prop.indexOf('on')==0) ret.addEventListener(prop.substring(2),b[prop],false);
else if(prop=="kids" && (prop=b[prop])) {
for(var i=0;i<prop.length;i++) ret.appendChild(prop[i]);
}
else if('style,accesskey,id,name,src,href,class'.indexOf(prop)!=-1) ret.setAttribute(prop, b[prop]);
else ret[prop]=b[prop];
} return ret;
}
|