[Jifty-commit] r4649 - in jifty/trunk: share/web/static/js/cssquery
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Dec 7 19:53:30 EST 2007
Author: sartak
Date: Fri Dec 7 19:53:30 2007
New Revision: 4649
Modified:
jifty/trunk/ (props changed)
jifty/trunk/share/web/static/js/cssquery/cssQuery.js
Log:
r48777 at onn: sartak | 2007-12-07 19:53:11 -0500
Another JS speedup: cache the results of selectAll. it's called only 8 times for /todo, but caching saves ~80ms.
Modified: jifty/trunk/share/web/static/js/cssquery/cssQuery.js
==============================================================================
--- jifty/trunk/share/web/static/js/cssquery/cssQuery.js (original)
+++ jifty/trunk/share/web/static/js/cssquery/cssQuery.js Fri Dec 7 19:53:30 2007
@@ -107,17 +107,31 @@
// -----------------------------------------------------------------------
// Jifty: special case of the descent selector. this is by far the most time
-// consuming code path of JS. special casing it does cut JS time a bit
+// consuming code path of JS. special casing and caching it saves roughly
+// 15% of JS time
+selectAllCache = {};
selectAll = function($results, $from) {
- // loop through current selection
- var $element, $subset, i, j;
- for (i = 0; i < $from.length; i++) {
- $subset = $from[i].getElementsByTagName("*");
- for (j = 0; ($element = $subset[j]); j++) {
- if (thisElement($element))
- $results.push($element);
- }
- }
+ var cache = selectAllCache[$from];
+ var i;
+
+ if (!cache) {
+ var $element, $subset, j;
+ var $elements = new Array();
+
+ for (i = 0; i < $from.length; i++) {
+ $subset = $from[i].getElementsByTagName("*");
+ for (j = 0; ($element = $subset[j]); j++) {
+ if (thisElement($element))
+ $elements.push($element);
+ }
+ }
+
+ selectAllCache[$from] = cache = $elements;
+ }
+
+ for (i in cache) {
+ $results.push(cache[i]);
+ }
};
// descendant selector
More information about the Jifty-commit
mailing list