Changeset 212

Show
Ignore:
Timestamp:
2007-04-05 22:17:56 (2 years ago)
Author:
MaierMan
Message:

caching is king: cache sorted all/active arrays.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/components/filterManager.js

    r173 r212  
    270270        this._filters = filters; 
    271271        this._idx = 0; 
    272         this._filters.sort(function(a,b) { 
    273                 if (a.defFilter && !b.defFilter) { 
    274                         return -1; 
    275                 } 
    276                 else if (!a.defFilter && b.defFilter) { 
    277                         return 1; 
    278                 } 
    279                 else if (a.defFilter) { 
    280                         if (a.id < b.id) { 
    281                                 return -1; 
    282                         } 
    283                         return 1; 
    284                 } 
    285                 var i = a.label.toLowerCase(), ii = b.label.toLowerCase(); 
    286                 return i < ii ? -1 : (i > ii ? 1 : 0); 
    287         }); 
    288272} 
    289273FilterEnumerator.prototype = { 
     
    385369                this._mustReload = false; 
    386370 
    387                 //error("DTAFM: reload"); 
    388371                this._filters = {}; 
     372                this._all = []; 
    389373                this._count = 0; 
    390374 
     
    410394                                filter.load(localizedLabel); 
    411395                                this._filters[filter.id] = filter; 
     396                                this._all.push(filter); 
    412397                                this._count++; 
    413398                        } 
     
    416401                        } 
    417402                } 
     403                this._all.sort( 
     404                        function(a,b) { 
     405                                if (a.defFilter && !b.defFilter) { 
     406                                        return -1; 
     407                                } 
     408                                else if (!a.defFilter && b.defFilter) { 
     409                                        return 1; 
     410                                } 
     411                                else if (a.defFilter) { 
     412                                        if (a.id < b.id) { 
     413                                                return -1; 
     414                                        } 
     415                                        return 1; 
     416                                } 
     417                                var i = a.label.toLowerCase(), ii = b.label.toLowerCase(); 
     418                                return i < ii ? -1 : (i > ii ? 1 : 0); 
     419                        } 
     420                );               
     421                this._active = this._all.filter(function(f) { return f.active; }); 
    418422 
    419423                // notify all observers 
     
    424428 
    425429        enumAll: function FM_enumAll() { 
    426                 var a = []; 
    427                 for (x in this._filters) { 
    428                         a.push(this._filters[x]); 
    429                 } 
    430                 return new FilterEnumerator(a); 
     430                return new FilterEnumerator(this._all); 
    431431        }, 
    432432        enumActive: function FM_enumActive(type) { 
    433                 var a = []; 
    434                 for (x in this._filters) { 
    435                         if (this._filters[x].active && this._filters[x].type & type) { 
    436                                 a.push(this._filters[x]); 
    437                         } 
    438                 } 
    439                 return new FilterEnumerator(a); 
     433                return new FilterEnumerator(this._active); 
    440434        }, 
    441435 
     
    448442 
    449443        matchActive: function FM_matchActive(test, type) { 
    450                 var e = this.enumActive(type); 
    451                 // we're a friend :p 
    452                 return e._filters.some(function(i) { return i.match(test); }); 
     444                return this._active.some(function(i) { return i.match(test); }); 
    453445        }, 
    454446 
     
    487479 
    488480        save: function FM_save() { 
    489                 var e = this.enumAll(); 
    490                 while (e.hasMoreElements()) { 
    491                         var f = e.getNext(); 
    492                         try { 
    493                                 f.save(); 
    494                         } catch (ex) { 
    495                                 error(ex); 
    496                         } 
    497                 } 
     481                this._all.forEach( 
     482                        function(f) { 
     483                                try { 
     484                                        f.save(); 
     485                                } catch (ex) { 
     486                                        error(ex); 
     487                                } 
     488                        }, 
     489                        this 
     490                ); 
    498491        }, 
    499492