Merge pull request #177 from NickCraver/master

Removing eval() for performance, usage was also causing variable collision in some minifiers
This commit is contained in:
Rob G 2012-11-21 13:05:51 -08:00
commit 57d892ca72

View File

@ -455,16 +455,15 @@
sortTime, i, j, k, c, cache, lc, s, e, order, orgOrderCol; sortTime, i, j, k, c, cache, lc, s, e, order, orgOrderCol;
if (tc.debug) { sortTime = new Date(); } if (tc.debug) { sortTime = new Date(); }
for (k = 0; k < bl; k++) { for (k = 0; k < bl; k++) {
dynamicExp = "sortWrapper = function(a,b) {";
cache = tc.cache[k]; cache = tc.cache[k];
lc = cache.normalized.length; lc = cache.normalized.length;
cache.normalized.sort(function(a, b) {
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
c = sortList[i][0]; c = sortList[i][0];
order = sortList[i][1]; order = sortList[i][1];
// fallback to natural sort since it is more robust // fallback to natural sort since it is more robust
s = /n/i.test(getCachedSortType(tc.parsers, c)) ? "Numeric" : "Text"; s = /n/i.test(getCachedSortType(tc.parsers, c)) ? "Numeric" : "Text";
s += order === 0 ? "" : "Desc"; s += order === 0 ? "" : "Desc";
e = "e" + i;
// get max column value (ignore sign) // get max column value (ignore sign)
if (/Numeric/.test(s) && tc.strings[c]) { if (/Numeric/.test(s) && tc.strings[c]) {
for (j = 0; j < lc; j++) { for (j = 0; j < lc; j++) {
@ -478,19 +477,12 @@
dir = (tc.strings[c]) ? tc.string[tc.strings[c]] || 0 : 0; dir = (tc.strings[c]) ? tc.string[tc.strings[c]] || 0 : 0;
} }
} }
dynamicExp += "var " + e + " = $.tablesorter.sort" + s + "(table,a[" + c + "],b[" + c + "]," + c + "," + mx + "," + dir + "); "; var sort = $.tablesorter["sort" + s](table, a[c], b[c], c, mx, dir);
dynamicExp += "if (" + e + ") { return " + e + "; } "; if (sort) { return sort; }
dynamicExp += "else { ";
} }
// if value is the same keep orignal order
orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0; orgOrderCol = (cache.normalized && cache.normalized[0]) ? cache.normalized[0].length - 1 : 0;
dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];"; return a[orgOrderCol] - b[orgOrderCol];
for (i=0; i < l; i++) { });
dynamicExp += "}; ";
}
dynamicExp += "return 0; ";
dynamicExp += "}; ";
cache.normalized.sort(eval(dynamicExp)); // sort using eval expression
} }
if (tc.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time", sortTime); } if (tc.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time", sortTime); }
} }