2
0
Эх сурвалжийг харах

use array for StringBuf in javascript

Nicolas Cannasse 17 жил өмнө
parent
commit
04365070b4

+ 1 - 0
doc/CHANGES.txt

@@ -12,6 +12,7 @@ TODO :
 	fixed bug in interfaces that define the method toString (haXe/PHP)
 	fixed bug in interfaces that define the method toString (haXe/PHP)
 	fixed bug in haxe.io.BytesInput.readBytes in Flash9 (was throwing Eof if full buffer can't be readed)
 	fixed bug in haxe.io.BytesInput.readBytes in Flash9 (was throwing Eof if full buffer can't be readed)
 	fixed implements/extends special classes when they are imported
 	fixed implements/extends special classes when they are imported
+	StringBuf now uses an array for JS implementation (around same on FF, faster on IE)
 
 
 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)

+ 21 - 4
std/StringBuf.hx

@@ -35,6 +35,8 @@ class StringBuf {
 	public function new() {
 	public function new() {
 		#if neko
 		#if neko
 			b = __make();
 			b = __make();
+		#elseif js
+			b = new Array();
 		#else
 		#else
 			b = "";
 			b = "";
 		#end
 		#end
@@ -46,6 +48,8 @@ class StringBuf {
 	public inline function add( ?x : Dynamic ) {
 	public inline function add( ?x : Dynamic ) {
 		#if neko
 		#if neko
 			__add(b,x);
 			__add(b,x);
+		#elseif js
+			b[b.length] = x;
 		#else
 		#else
 			b += x;
 			b += x;
 		#end
 		#end
@@ -62,6 +66,8 @@ class StringBuf {
 				b += s.substr(pos);
 				b += s.substr(pos);
 			else
 			else
 				b += s.substr(pos,len);
 				b += s.substr(pos,len);
+		#elseif js
+			b[b.length] = s.substr(pos,len);
 		#else
 		#else
 			b += s.substr(pos,len);
 			b += s.substr(pos,len);
 		#end
 		#end
@@ -73,10 +79,12 @@ class StringBuf {
 	public inline function addChar( c : Int ) untyped {
 	public inline function addChar( c : Int ) untyped {
 		#if neko
 		#if neko
 			__add_char(b,c);
 			__add_char(b,c);
-		#elseif (flash9 || js || php)
-			b += String.fromCharCode(c);
-		#elseif flash
+		#elseif js
+			b[b.length] = String.fromCharCode(c);
+		#elseif (flash && !flash9)
 			b += String["fromCharCode"](c);
 			b += String["fromCharCode"](c);
+		#else
+			b += String.fromCharCode(c);
 		#end
 		#end
 	}
 	}
 
 
@@ -87,12 +95,21 @@ class StringBuf {
 	public inline function toString() : String {
 	public inline function toString() : String {
 		#if neko
 		#if neko
 			return new String(__string(b));
 			return new String(__string(b));
+		#elseif js
+			return b.join("");
 		#else
 		#else
 			return b;
 			return b;
 		#end
 		#end
 	}
 	}
 
 
-	private var b : #if neko Dynamic #else String #end;
+	private var b :
+	#if neko
+		Dynamic
+	#elseif js
+		Array<Dynamic>
+	#else
+		String
+	#end;
 
 
 #if neko
 #if neko
 	static var __make : Dynamic = neko.Lib.load("std","buffer_new",0);
 	static var __make : Dynamic = neko.Lib.load("std","buffer_new",0);