Browse Source

speedup Array.remove

Nicolas Cannasse 16 years ago
parent
commit
3ddd173e5a
3 changed files with 12 additions and 26 deletions
  1. 4 10
      std/flash/Boot.hx
  2. 4 6
      std/flash9/Boot.hx
  3. 4 10
      std/js/Boot.hx

+ 4 - 10
std/flash/Boot.hx

@@ -224,16 +224,10 @@ class Boot {
 				this["splice"](i,0,x);
 			};
 			Array.prototype["remove"] = function(obj) {
-				var i = 0;
-				var l = this["length"];
-				while( i < l ) {
-					if( this[i] == obj ) {
-						this["splice"](i,1);
-						return true;
-					}
-					i++;
-				}
-				return false;
+				var idx = this["indexOf"](obj);
+				if( idx == -1 ) return false;
+				this["splice"](idx,1);
+				return true;
 			}
 			Array.prototype["iterator"] = function() {
 				return {

+ 4 - 6
std/flash9/Boot.hx

@@ -44,12 +44,10 @@ class Boot extends flash.display.MovieClip, implements Dynamic {
 				this.splice(i,0,x);
 			};
 			aproto.remove = function(obj) {
-				for( i in 0...this.length )
-					if( this[i] == obj ) {
-						this.splice(i,1);
-						return true;
-					}
-				return false;
+				var idx = this.indexOf(obj);
+				if( idx == -1 ) return false;
+				this.splice(idx,1);
+				return true;
 			}
 			aproto.iterator = function() {
 				var cur = 0;

+ 4 - 10
std/js/Boot.hx

@@ -200,16 +200,10 @@ class Boot {
 				this.splice(i,0,x);
 			};
 			Array.prototype.remove = function(obj) {
-				var i = 0;
-				var l = this.length;
-				while( i < l ) {
-					if( this[i] == obj ) {
-						this.splice(i,1);
-						return true;
-					}
-					i++;
-				}
-				return false;
+				var idx = this.indexOf(obj);
+				if( idx == -1 ) return false;
+				this.splice(idx,1);
+				return true;
 			}
 			Array.prototype.iterator = function() {
 				return {