Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#9875 closed task (fixed)

[cla/patch] dijit.WidgetSet - faster toArray() method

Reported by: Les Owned by: bill
Priority: high Milestone: 1.4
Component: Dijit Version: 1.3.2
Keywords: dijit.WidgetSet Cc:
Blocked By: Blocking:

Description

This simple change results in 2x speed improvement in some browsers.

toArray: function() {
	var ar = [];
	for(id in this._hash){
		arry.push(this._hash[id]);
	}
	return ar;
}

The current code calls an anonymous function on each iteration.

toArray: function(){
	var ar = [];
	this.forEach(function(w){
		ar.push(w); // ^ i, ar[i] = w;
	});
	return ar; // Array
}

Change History (7)

comment:1 Changed 10 years ago by Les

Fixed typo

toArray: function() {
	var ar = [];
	for(id in this._hash){
		ar.push(this._hash[id]);
	}
	return ar;
}

comment:2 Changed 10 years ago by bill

Component: GeneralDijit
Keywords: dijit.WidgetSet added; ijit.WidgetSet removed
Owner: anonymous deleted

That's true, although I didn't think many people were using toArray(). But I guess it's worth the change. See also #4122.

comment:3 Changed 10 years ago by Les

dijit.WidgetSet?.filter() should also be converted to a for loop. This method is used quite often.

comment:4 Changed 10 years ago by bill

Milestone: tbd1.4
Owner: set to bill
Status: newassigned

BTW where is filter() used? I can't think of anyone using it offhand but maybe there are plades.

comment:5 Changed 10 years ago by Les

byClass uses filter. I used byClass in the past.

comment:6 Changed 10 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [20107]) Dijit performance optimizations from Les Szklanny (CLA on file), thanks! Fixes #9885, #9875, #9879, refs #9131. !strict

comment:7 Changed 10 years ago by bill

Type: enhancementtask

seems like these aren't really enhancements from the users' point of view, labeling as tasks instead

Note: See TracTickets for help on using tickets.