Prechádzať zdrojové kódy

[lua] remove usage of StringBuf in base classes with Table.concat.

Justin Donaldson 9 rokov pred
rodič
commit
5c67292c22
2 zmenil súbory, kde vykonal 17 pridanie a 20 odobranie
  1. 6 6
      std/lua/Boot.hx
  2. 11 14
      std/lua/_std/Array.hx

+ 6 - 6
std/lua/Boot.hx

@@ -222,16 +222,16 @@ class Boot {
 				else if (Lua.next(o) == null) "{}";
 				else {
 					var fields = Reflect.fields(o);
-					var buffer = new StringBuf();
+					var buffer:Table<Int,String> = Table.create();
 					var first = true;
-					buffer.add("{ ");
+					Table.insert(buffer,"{ ");
 					for (f in fields){
 						if (first) first = false;
-						else buffer.add(", ");
-						buffer.add('${s}${Std.string(f)} : ${untyped Std.string(o[f])}');
+						else Table.insert(buffer,", ");
+						Table.insert(buffer,'${s}${Std.string(f)} : ${untyped Std.string(o[f])}');
 					}
-					buffer.add(" }");
-					buffer.toString();
+					Table.insert(buffer, " }");
+					Table.concat(buffer, "");
 				}
 			};
 			default : {

+ 11 - 14
std/lua/_std/Array.hx

@@ -33,14 +33,11 @@ class Array<T> {
 		return ret;
 	}
 	public function join( sep : String ) : String {
-		var sb = new StringBuf();
-		var first = true;
+		var tbl : lua.Table<Int,String> = lua.Table.create();
 		for (i in iterator()){
-			if (first) first = false;
-			else sb.add(sep);
-			sb.add(Std.string(i));
+			lua.Table.insert(tbl,Std.string(i));
 		}
-		return sb.toString();
+		return lua.Table.concat(tbl,sep);
 	}
 
 	public function pop() : Null<T> {
@@ -101,11 +98,11 @@ class Array<T> {
 	}
 
 	public function toString() : String {
-		var sb = new StringBuf();
-		sb.add("[");
-		sb.add(join(","));
-		sb.add("]");
-		return sb.toString();
+		var tbl : lua.Table<Int,String> = lua.Table.create();
+		lua.Table.insert(tbl, '[');
+		lua.Table.insert(tbl, join(","));
+		lua.Table.insert(tbl, ']');
+		return lua.Table.concat(tbl,"");
 	}
 
 	public function unshift( x : T ) : Void {
@@ -134,9 +131,9 @@ class Array<T> {
 				for (j in i...length-1){
 					this[j] = this[j+1];
 				}
-				// We need to decrement the length variable, and set its 
-				// value to null to avoid hanging on to a reference in the 
-				// underlying lua table.  
+				// We need to decrement the length variable, and set its
+				// value to null to avoid hanging on to a reference in the
+				// underlying lua table.
 				this[length-1] = null;
 				// Do this in two steps to avoid re-updating the __index metamethod
 				length--;