Permalink
Browse files

Some minor performance tweaks:

- Cache the nsNormalize() results so we don't have to call $.camelcase() every time jqmData() is called.

- Move the regexp used in our monkey patched $.find outside of the function to save some regex compilation cycles.
  • Loading branch information...
1 parent e17e29b commit 488e8f70adb61d842b5466bf1ea22d34197c9f69 @jblas jblas committed Nov 8, 2011
Showing with 11 additions and 4 deletions.
  1. +11 −4 js/jquery.mobile.core.js
@@ -8,6 +8,8 @@
(function( $, window, undefined ) {
+ var nsNormalizeDict = {};
+
// jQuery.mobile configurable options
$.extend( $.mobile, {
@@ -119,14 +121,18 @@
}, 150 );
},
+ // Expose our cache for testing purposes.
+ nsNormalizeDict: nsNormalizeDict,
+
// Take a data attribute property, prepend the namespace
- // and then camel case the attribute string
+ // and then camel case the attribute string. Add the result
+ // to our nsNormalizeDict so we don't have to do this again.
nsNormalize: function( prop ) {
if ( !prop ) {
return;
}
- return $.camelCase( $.mobile.ns + prop );
+ return nsNormalizeDict[ prop ] || ( nsNormalizeDict[ prop ] = $.camelCase( $.mobile.ns + prop ) );
},
getInheritedTheme: function( el, defaultTheme ) {
@@ -213,10 +219,11 @@
};
// Monkey-patching Sizzle to filter the :jqmData selector
- var oldFind = $.find;
+ var oldFind = $.find,
+ jqmDataRE = /:jqmData\(([^)]*)\)/g;
$.find = function( selector, context, ret, extra ) {
- selector = selector.replace(/:jqmData\(([^)]*)\)/g, "[data-" + ( $.mobile.ns || "" ) + "$1]");
+ selector = selector.replace( jqmDataRE, "[data-" + ( $.mobile.ns || "" ) + "$1]" );
return oldFind.call( this, selector, context, ret, extra );
};

0 comments on commit 488e8f7

Please sign in to comment.