Browse Source

no indexOf in AS2 array

Nicolas Cannasse 16 years ago
parent
commit
6d5a935d56
3 changed files with 17 additions and 5 deletions
  1. 1 1
      doc/CHANGES.txt
  2. 10 4
      std/flash/Boot.hx
  3. 6 0
      tests/unit/TestBasetypes.hx

+ 1 - 1
doc/CHANGES.txt

@@ -39,7 +39,7 @@ TODO :
 	compiler : separated basic and advanced commandline options
 	compiler : separated basic and advanced commandline options
 	compiler : fixed printing of sub-function types
 	compiler : fixed printing of sub-function types
 	genHX : fixed generation of classes that extends another class (shouldn't be turned into enums)
 	genHX : fixed generation of classes that extends another class (shouldn't be turned into enums)
-	speedup Array.remove on flash/flash9/js
+	speedup Array.remove on flash9/js
 
 
 2008-11-23: 2.02
 2008-11-23: 2.02
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)

+ 10 - 4
std/flash/Boot.hx

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

+ 6 - 0
tests/unit/TestBasetypes.hx

@@ -11,6 +11,12 @@ class TestBasetypes extends Test {
 		eq( a[3], null );
 		eq( a[3], null );
 		eq( a[1000], null );
 		eq( a[1000], null );
 		eq( a[-1], null );
 		eq( a[-1], null );
+
+		a.remove(2);
+		eq( a.length, 2);
+		eq( a[0], 1 );
+		eq( a[1], 3 );
+		eq( a[2], null );
 	}
 	}
 
 
 	function testString() {
 	function testString() {