
const ATOM_SERVICE = Components.classes['@mozilla.org/atom-service;1'].getService(Components.interfaces.nsIAtomService);

function sbCustomTreeView(aColIDs, aItems)
{
	this._items = aItems;
	this._rowCount = aItems.length;
	this.colIDs = aColIDs;
}


sbCustomTreeView.prototype = 
{
	get rowCount()
	{
		return this._rowCount;
	},
	getCellText: function(row, col)
	{
		return this._items[row][col.index];
	},
	setCellText: function(row, col, val)
	{
		this._items[row][col.index] = val;
	},
	setTree: function(tree)
	{
		this._treeBox = tree;
	},
	cycleHeader : function(colID, elem){},
	getRowProperties : function(index, properties){},
	getCellProperties : function(row, colID, properties){},
	getColumnProperties : function(colID, colElem, properties){},
	isContainer : function(row){},
	isContainerOpen : function(row){},
	isContainerEmpty : function(row){},
	isSeparator : function(row){},
	isSorted : function(row){},
	canDrop : function(index, orient){},
	canDropOn : function(index){},
	canDropBeforeAfter : function(index, before){},
	drop : function(index, orient){},
	getParentIndex : function getParentIndex(index){ return -1; },
	hasNextSibling : function(index, afterIndex){},
 	getLevel : function(index){},
	getImageSrc : function(row, col){},
	getProgressMode : function(row, colID){},
	getCellValue : function(row, colID){},
	selectionChanged : function(){},
	cycleCell : function(row, colID){},
	isEditable : function(row, colID){},
	toggleOpenState : function(index){},
	performAction : function(action){},
	performActionOnRow : function(action, row){},
	performActionOnCell : function(action, row, colID){},
};


var sbCustomTreeUtil = {

	sortItems : function(aService, aColElem)
	{
		var asc = aColElem.getAttribute("sortDirection") != "ascending";
		var elems = aService.TREE.firstChild.childNodes;
		for ( var i = 0; i < elems.length; i++ )
		{
			elems[i].removeAttribute("sortDirection");
		}
		if ( !asc ) {
			aService.treeItems.reverse();
		} else {
			this.heapSort(aService.treeItems, aColElem.getAttribute("sortIndex"));
		}
		aColElem.setAttribute("sortDirection", asc ? "ascending" : "descending");
		aService.initTree();
	},

	heapSort : function(array, k)
	{
		var h, i, j, n;
		array[array.length] = array[0];
		var N = array.length - 1;
		for( h=N; h>0; h-- ) {
			i = h;
			n = array[i];
			while( (j=i*2) <= N ) {
				if( (j<N) && (array[j][k]<array[j+1][k]) ) j++;
				if( n[k] >= array[j][k] ) break;
				array[i] = array[j];
				i = j;
			}
			array[i] = n;
		}
		while( N>1 ) {
			n = array[N];
			array[N] = array[1];
			N--;
			i = 1;
			while( (j=i*2)<=N ) {
				if( (j<N) && (array[j][k]<array[j+1][k]) ) j++;
				if( n[k] >= array[j][k] ) break;
				array[i] = array[j];
				i = j;
			}
			array[i] = n;
		}
		for( i=0; i<array.length-1; i++ ) array[i] = array[i+1];
		array.length--;
	},

	getSelection : function(aTree)
	{
		var retArray = [];
		for ( var rc = 0; rc < aTree.view.selection.getRangeCount(); rc++ )
		{
			var start = {}, end = {};
			aTree.view.selection.getRangeAt(rc, start, end);
			for ( var i = start.value; i <= end.value; i++ )
			{
				retArray.push(i);
			}
		}
		return retArray;
	},

};



@@ -1978,44 +1978,31 @@
 e %7B%0A
-%09%09%09this.heapSort(aService.treeItems,
+            var index =
  aCo
@@ -2036,790 +2036,308 @@
 ex%22)
-)
 ;%0A
-%09%09%7D%0A%09%09aColElem.setAttribute(%22sortDirection%22, asc ? %22ascending%22 : %22descending%22);%0A%09%09aService.initTree();%0A%09%7D,%0A%0A%09heapSort : function(array, k)%0A%09%7B%0A%09%09var h, i, j, n;%0A%09%09array%5Barray.length%5D = array%5B0%5D;%0A%09%09var N = array.length - 1;%0A%09%09for( h=N; h%3E0; h-- ) %7B%0A%09%09%09i = h;%0A%09%09%09n = array%5Bi%5D;%0A%09%09%09while( (j=i*2) %3C= N ) %7B%0A%09%09%09%09if( (j%3CN) && (array%5Bj%5D%5Bk%5D%3Carray%5Bj+1%5D%5Bk%5D) ) j++;%0A%09%09%09%09if( n%5Bk%5D %3E= array%5Bj%5D%5Bk%5D 
+            aService.treeItems.sort(function(a, b)%7B%0A                if (a%5Bindex%5D %3E b%5Bindex%5D) return 1;%0A                if (a%5Bindex%5D %3C b%5Bindex%5D
 ) 
-b
 re
-ak;%0A%09%09%09%09array%5Bi%5D = array%5Bj%5D;%0A%09%09%09%09i = j;%0A%09%09%09%7D%0A%09%09%09array%5Bi%5D = n;%0A%09%09%7D%0A%09%09while( N%3E1 ) %7B%0A%09%09%09n = array%5BN%5D;%0A%09%09%09array%5BN%5D = array%5B1%5D;%0A%09%09%09N--;%0A%09%09%09i = 1;%0A%09%09%09while( (j=i*2)%3C=N ) %7B%0A%09%09%09%09if( (j%3CN) && (array%5Bj%5D%5Bk%5D%3Carray%5Bj+1%5D%5Bk%5D) ) j++;%0A%09%09%09%09if( n%5Bk%5D %3E= array%5Bj%5D%5Bk%5D ) break;%0A%09%09%09%09array%5Bi%5D = array%5Bj%5D;%0A%09%09%09%09i = j;%0A%09%09%09%7D%0A%09%09%09array%5Bi%5D = n;%0A%09%09%7D%0A%09%09for( i=0; i%3Carray.length-1; i++ ) array%5Bi%5D = array%5Bi+1%5D;%0A%09%09array.length--
+turn -1;%0A                return 0;%0A            %7D);%0A%09%09%7D%0A%09%09aColElem.setAttribute(%22sortDirection%22, asc ? %22ascending%22 : %22descending%22);%0A%09%09aService.initTree()
 ;%0A%09%7D

Replace heapsort with Array.prototype.sort (mergesort), which is stable and has better performance.