Browse Source

optimized Std.int(123) and Std.int(123.45)

Nicolas Cannasse 13 years ago
parent
commit
68b5e84f41
2 changed files with 13 additions and 0 deletions
  1. 2 0
      doc/CHANGES.txt
  2. 11 0
      optimizer.ml

+ 2 - 0
doc/CHANGES.txt

@@ -10,6 +10,8 @@
 	flash : removed wrapping for Xml nodes, use instead specific compare when comparing two typed nodes
 	js : use new haxe.xml.Parser (faster, not based on Regexp)
 	flash : fixed completion issue with for( x in Vector )
+	all : forbid static inline var when not a constant (after optimization)
+	all : optimized Std.int(123) and Std.int(123.45)
 
 2012-04-14: 2.09
 	all : optimized const == const and const != const (with different const types)

+ 11 - 0
optimizer.ml

@@ -45,6 +45,17 @@ let api_inline ctx c field params p =
 	| ([],"Type"),"enumIndex",[{ eexpr = TCall({ eexpr = TEnumField (en,f) },pl) }] when List.for_all (fun e -> not (has_side_effect e)) pl ->
 		let c = (try PMap.find f en.e_constrs with Not_found -> assert false) in
 		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 }
+	| ([],"Std"),"int",[{ eexpr = TConst (TFloat f) }] ->
+		let f = float_of_string f in
+		(match classify_float f with
+		| FP_infinite | FP_nan ->
+			None
+		| _ when f <= Int32.to_float Int32.min_int -. 1. || f >= Int32.to_float Int32.max_int +. 1. ->
+			None (* out range, keep platform-specific behavior *)
+		| _ ->
+			Some { eexpr = TConst (TInt (Int32.of_float f)); etype = ctx.t.tint; epos = p })
 	| _ ->
 		None