[Jifty-commit] r4650 - in jifty/trunk: share/web/static/js/cssquery

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Dec 7 21:43:00 EST 2007


Author: sartak
Date: Fri Dec  7 21:42:58 2007
New Revision: 4650

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/share/web/static/js/cssquery/cssQuery.js

Log:
 r48779 at onn:  sartak | 2007-12-07 21:42:41 -0500
 Speed up selection by class by using indexOf with space padding instead of regex


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 21:42:58 2007
@@ -5,6 +5,9 @@
 
 	Modifed by Nelson Elhage <nelhage at bestpractical.com>
 	(2006-06-21) to optimize selection by ID on non-IE browsers
+
+    Modified by Shawn M Moore <sartak at bestpractical.com>
+    (2007-12-07) sped up thisElement, descendent selector, and class selector
 */
 
 // the following functions allow querying of the DOM using CSS selectors
@@ -162,12 +165,14 @@
 
 // class selector
 selectors["."] = function($results, $from, $className) {
-	// create a RegExp version of the class
-	$className = new RegExp("(^|\\s)" + $className + "(\\s|$)");
-	// loop through current selection and check class
-	var $element, i;
-	for (i = 0; ($element = $from[i]); i++)
-		if ($className.test($element.className)) $results.push($element);
+    $className = " " + $className + " ";
+    var $element, i;
+    for (i = 0; ($element = $from[i]); i++) {
+        var classes = " " + $element.className + " ";
+        if (classes.indexOf($className) > -1) {
+            $results.push($element);
+        }
+    }
 };
 
 // pseudo-class selector


More information about the Jifty-commit mailing list