Skip to content
This repository
Browse code

Uh, yeah, I'll take back another 700 msecs on WP7.5 (Mango) and 200 m…

…secs on iPad. Thank You.

- Don't set the item class on the list item or it's btn-inner children until after the main processing loop. We now use a dictionary of item-classes to track what items get what set of classes and then set them all afterwards. This cuts down the per-item addClass() and children() function overhead significantly and gets us big wins on platforms like WP 7.5
  • Loading branch information...
commit 3353649a2982248b4d96ebb0b8fe370ee8962cd8 1 parent 0e0435e
Kin Blas authored November 14, 2011

Showing 1 changed file with 21 additions and 1 deletion. Show diff stats Hide diff stats

  1. 22  js/jquery.mobile.listview.js
22  js/jquery.mobile.listview.js
@@ -154,6 +154,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
154 154
 			listspliticon = $list.jqmData( "spliticon" ),
155 155
 			li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
156 156
 			counter = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? 0 : 1,
  157
+			itemClassDict = {},
157 158
 			item, itemClass, itemTheme,
158 159
 			a, last, splittheme, countParent, icon, imgParents, img;
159 160
 
@@ -238,7 +239,26 @@ $.widget( "mobile.listview", $.mobile.widget, {
238 239
 					.prepend( "<span class='ui-li-dec'>" + (counter++) + ". </span>" );
239 240
 			}
240 241
 
241  
-			item.addClass( itemClass ).children( ".ui-btn-inner" ).addClass( itemClass );
  242
+			// Instead of setting item class directly on the list item and its
  243
+			// btn-inner at this point in time, push the item into a dictionary
  244
+			// that tells us what class to set on it so we can do this after this
  245
+			// processing loop is finished.
  246
+
  247
+			if ( !itemClassDict[ itemClass ] ) {
  248
+				itemClassDict[ itemClass ] = [];
  249
+			}
  250
+
  251
+			itemClassDict[ itemClass ].push( item[ 0 ] );
  252
+		}
  253
+
  254
+		// Set the appropriate listview item classes on each list item
  255
+		// and their btn-inner elements. The main reason we didn't do this
  256
+		// in the for-loop above is because we can eliminate per-item function overhead
  257
+		// by calling addClass() and children() once or twice afterwards. This
  258
+		// can give us a significant boost on platforms like WP7.5.
  259
+
  260
+		for ( itemClass in itemClassDict ) {
  261
+			$( itemClassDict[ itemClass ] ).addClass( itemClass ).children( ".ui-btn-inner" ).addClass( itemClass );
242 262
 		}
243 263
 
244 264
 		$list.find( "h1, h2, h3, h4, h5, h6" ).addClass( "ui-li-heading" )

0 notes on commit 3353649

Please sign in to comment.
Something went wrong with that request. Please try again.