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

Commit b9fbfb3

Browse files
committed
perf(jqLite): don't use reflection to access expandoId
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.
1 parent 3d03e19 commit b9fbfb3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/jqLite.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@
9898
* @returns {Object} jQuery object.
9999
*/
100100

101+
JQLite.expando = 'ng';
102+
101103
var jqCache = JQLite.cache = {},
102-
jqName = JQLite.expando = 'ng-' + new Date().getTime(),
103104
jqId = 1,
104105
addEventListenerFn = (window.document.addEventListener
105106
? function(element, type, fn) {element.addEventListener(type, fn, false);}
@@ -270,7 +271,7 @@ function jqLiteOff(element, type, fn, unsupported) {
270271
}
271272

272273
function jqLiteRemoveData(element, name) {
273-
var expandoId = element[jqName],
274+
var expandoId = element.ng,
274275
expandoStore = jqCache[expandoId];
275276

276277
if (expandoStore) {
@@ -284,17 +285,17 @@ function jqLiteRemoveData(element, name) {
284285
jqLiteOff(element);
285286
}
286287
delete jqCache[expandoId];
287-
element[jqName] = undefined; // ie does not allow deletion of attributes on elements.
288+
element.ng = undefined; // don't delete DOM expandos. IE and Chrome don't like it
288289
}
289290
}
290291

291292
function jqLiteExpandoStore(element, key, value) {
292-
var expandoId = element[jqName],
293+
var expandoId = element.ng,
293294
expandoStore = jqCache[expandoId || -1];
294295

295296
if (isDefined(value)) {
296297
if (!expandoStore) {
297-
element[jqName] = expandoId = jqNextId();
298+
element.ng = expandoId = jqNextId();
298299
expandoStore = jqCache[expandoId] = {};
299300
}
300301
expandoStore[key] = value;

0 commit comments

Comments
 (0)