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

Commit 960a841

Browse files
committed
perf(jqLite): don't use forEach in #off
off() is called on each element removal, so we want to make it as fast as possible
1 parent 01b10d7 commit 960a841

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/jqLite.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,21 @@ function jqLiteDealoc(element, onlyDescendants){
262262
function jqLiteOff(element, type, fn, unsupported) {
263263
if (isDefined(unsupported)) throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument');
264264

265-
var events = jqLiteExpandoStore(element, 'events'),
266-
handle = jqLiteExpandoStore(element, 'handle');
265+
var events = jqLiteExpandoStore(element, 'events');
266+
var handle = jqLiteExpandoStore(element, 'handle');
267+
var i;
268+
var types;
267269

268270
if (!handle) return; //no listeners registered
269271

270272
if (isUndefined(type)) {
271-
forEach(events, function(eventHandler, type) {
272-
removeEventListenerFn(element, type, eventHandler);
273+
types = Object.keys(events);
274+
i = types.length;
275+
while (i--) {
276+
type = types[i];
277+
removeEventListenerFn(element, type, events[type]);
273278
delete events[type];
274-
});
279+
}
275280
} else {
276281
forEach(type.split(' '), function(type) {
277282
if (isUndefined(fn)) {

0 commit comments

Comments
 (0)