1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

code review: avoid Array.splice/unshift

The array size stays the same, items are just moved around.
This commit is contained in:
Raymond Hill 2017-12-22 09:37:26 -05:00
parent 607968de7f
commit 4ab63e70fe
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -373,8 +373,11 @@
lookup: function(key) {
var value = this.map.get(key);
if ( value !== undefined && this.array[0] !== key ) {
this.array.splice(this.array.indexOf(key), 1);
this.array.unshift(key);
var i = this.array.indexOf(key);
do {
this.array[i] = this.array[i-1];
} while ( --i );
this.array[0] = key;
}
return value;
},