Просмотр исходного кода

use array for StringBuf in javascript

Nicolas Cannasse 17 лет назад
Родитель
Сommit
04365070b4
2 измененных файлов с 22 добавлено и 4 удалено
  1. 1 0
      doc/CHANGES.txt
  2. 21 4
      std/StringBuf.hx

+ 1 - 0
doc/CHANGES.txt

@@ -12,6 +12,7 @@ TODO :
 	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 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
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)

+ 21 - 4
std/StringBuf.hx

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