Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
perf(jqLite): don't use reflection to access expandoId
Browse files Browse the repository at this point in the history
Since we allow only one copy of Angular to be loaded at a time it doesn't
make much sense randomly generate the expando property name and then be
forced to use slow reflective calles to retrieve the IDs.
  • Loading branch information
IgorMinar authored and rodyhaddad committed Jun 13, 2014
1 parent 04468db commit ea9a130
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/jqLite.js
Expand Up @@ -99,8 +99,9 @@
* @returns {Object} jQuery object.
*/

JQLite.expando = 'ng';

var jqCache = JQLite.cache = {},
jqName = JQLite.expando = 'ng' + new Date().getTime(),
jqId = 1,
addEventListenerFn = (window.document.addEventListener
? function(element, type, fn) {element.addEventListener(type, fn, false);}
Expand Down Expand Up @@ -271,7 +272,7 @@ function jqLiteOff(element, type, fn, unsupported) {
}

function jqLiteRemoveData(element, name) {
var expandoId = element[jqName],
var expandoId = element.ng,
expandoStore = jqCache[expandoId];

if (expandoStore) {
Expand All @@ -285,17 +286,17 @@ function jqLiteRemoveData(element, name) {
jqLiteOff(element);
}
delete jqCache[expandoId];
element[jqName] = undefined; // ie does not allow deletion of attributes on elements.
element.ng = undefined; // don't delete DOM expandos. IE and Chrome don't like it
}
}

function jqLiteExpandoStore(element, key, value) {
var expandoId = element[jqName],
var expandoId = element.ng,
expandoStore = jqCache[expandoId || -1];

if (isDefined(value)) {
if (!expandoStore) {
element[jqName] = expandoId = jqNextId();
element.ng = expandoId = jqNextId();
expandoStore = jqCache[expandoId] = {};
}
expandoStore[key] = value;
Expand Down

0 comments on commit ea9a130

Please sign in to comment.