Small indexOf optimization.

This commit is contained in:
Zixaphir 2013-04-30 17:22:08 -07:00
parent 9de43acd3d
commit 9ba7f2c3f2
5 changed files with 12 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
* 4chan X - Version 1.1.3 - 2013-04-28 * 4chan X - Version 1.1.3 - 2013-04-30
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

@ -18,7 +18,7 @@
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.1.3 - 2013-04-28 * 4chan X - Version 1.1.3 - 2013-04-30
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -335,7 +335,7 @@
i = this.length; i = this.length;
while (i--) { while (i--) {
if (this[i] === object) { if (this[i] === object) {
break; return i;
} }
} }
return i; return i;
@ -349,6 +349,7 @@
arg = args[_i]; arg = args[_i];
this.push.apply(this, arg); this.push.apply(this, arg);
} }
return this;
}; };
Array.prototype.remove = function(object) { Array.prototype.remove = function(object) {

View File

@ -18,7 +18,7 @@
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAgMAAAAqbBEUAAAACVBMVEUAAGcAAABmzDNZt9VtAAAAAXRSTlMAQObYZgAAAHFJREFUKFOt0LENACEIBdBv4Qju4wgWanEj3D6OcIVMKaitYHEU/jwTCQj8W75kiVCSBvdQ5/AvfVHBin11BgdRq3ysBgfwBDRrj3MCIA+oAQaku/Q1cNctrAmyDl577tOThYt/Y1RBM4DgOHzM0HFTAyLukH/cmRnqAAAAAElFTkSuQmCC
// ==/UserScript== // ==/UserScript==
/* /*
* 4chan X - Version 1.1.3 - 2013-04-28 * 4chan X - Version 1.1.3 - 2013-04-30
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -332,7 +332,7 @@
i = this.length; i = this.length;
while (i--) { while (i--) {
if (this[i] === object) { if (this[i] === object) {
break; return i;
} }
} }
return i; return i;
@ -346,6 +346,7 @@
arg = args[_i]; arg = args[_i];
this.push.apply(this, arg); this.push.apply(this, arg);
} }
return this;
}; };
Array.prototype.remove = function(object) { Array.prototype.remove = function(object) {

View File

@ -1,5 +1,5 @@
/* /*
* 4chan X - Version 1.1.3 - 2013-04-28 * 4chan X - Version 1.1.3 - 2013-04-30
* *
* Licensed under the MIT license. * Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE * https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -314,7 +314,7 @@
i = this.length; i = this.length;
while (i--) { while (i--) {
if (this[i] === object) { if (this[i] === object) {
break; return i;
} }
} }
return i; return i;
@ -328,6 +328,7 @@
arg = args[_i]; arg = args[_i];
this.push.apply(this, arg); this.push.apply(this, arg);
} }
return this;
}; };
Array.prototype.remove = function(object) { Array.prototype.remove = function(object) {

View File

@ -16,14 +16,14 @@ Array::contains = (object) ->
Array::indexOf = (object) -> Array::indexOf = (object) ->
i = @length i = @length
while i-- while i--
break if @[i] is object return i if @[i] is object
return i return i
Array::pushArrays = -> Array::pushArrays = ->
args = arguments args = arguments
for arg in args for arg in args
@push.apply @, arg @push.apply @, arg
return return @
Array::remove = (object) -> Array::remove = (object) ->
if (index = @indexOf object) > -1 if (index = @indexOf object) > -1