Forráskód Böngészése

removed use_native_add, instead use optimization of Std.string for some simple cases

Nicolas Cannasse 13 éve
szülő
commit
2d3877d315
2 módosított fájl, 12 hozzáadás és 7 törlés
  1. 12 0
      optimizer.ml
  2. 0 7
      typer.ml

+ 12 - 0
optimizer.ml

@@ -47,6 +47,18 @@ let api_inline ctx c field params p =
 		Some (mk (TConst (TInt (Int32.of_int c.ef_index))) ctx.t.tint p)
 	| ([],"Std"),"int",[{ eexpr = TConst (TInt _) } as e] ->
 		Some { e with epos = p }
+	| ([],"String"),"fromCharCode",[{ eexpr = TConst (TInt i) }] when i > 0l && i < 128l ->
+		Some (mk (TConst (TString (String.make 1 (char_of_int (Int32.to_int i))))) ctx.t.tstring p)
+	| ([],"Std"),"string",[{ eexpr = TConst c } as e] ->
+		(match c with
+		| TString s ->
+			Some { e with epos = p }
+		| TInt i ->
+			Some { eexpr = TConst (TString (Int32.to_string i)); epos = p; etype = ctx.t.tstring }
+		| TBool b ->
+			Some { eexpr = TConst (TString (if b then "true" else "false")); epos = p; etype = ctx.t.tstring }
+		| _ ->
+			None)
 	| ([],"Std"),"int",[{ eexpr = TConst (TFloat f) }] ->
 		let f = float_of_string f in
 		(match classify_float f with

+ 0 - 7
typer.ml

@@ -1007,15 +1007,8 @@ let rec type_binop ctx op e1 e2 p =
 	let tint = ctx.t.tint in
 	let tfloat = ctx.t.tfloat in
 	let tstring = ctx.t.tstring in
-	let use_native_add() =
-		match ctx.curclass.cl_path with
-		| ([],"StringBuf") -> true
-		| _ -> false
-	in
 	let to_string e =
 		match classify e.etype with
-		| KDyn when use_native_add() ->
-			e
 		| KUnk | KDyn | KParam _ | KOther ->
 			let std = type_type ctx ([],"Std") e.epos in
 			let acc = acc_get ctx (type_field ctx std "string" e.epos MCall) e.epos in