Browse Source

use Buffer instead of concatenating strings

Dan Korostelev 8 years ago
parent
commit
250dcfc8c3
1 changed files with 5 additions and 8 deletions
  1. 5 8
      src/generators/genpy.ml

+ 5 - 8
src/generators/genpy.ml

@@ -1519,17 +1519,14 @@ module Printer = struct
 				let s_el = (print_call_args pctx e1 el) in
 				let s_el = (print_call_args pctx e1 el) in
 				Printf.sprintf "super().__init__(%s)" s_el
 				Printf.sprintf "super().__init__(%s)" s_el
 			| ("python_Syntax._pythonCode"),[({ eexpr = TConst (TString code) } as ecode); {eexpr = TArrayDecl tl}] ->
 			| ("python_Syntax._pythonCode"),[({ eexpr = TConst (TString code) } as ecode); {eexpr = TArrayDecl tl}] ->
-				let r = ref "" in
-				let f_string s =
-					r := !r ^ s
-				in
-				let f_expr e =
-					r:= !r ^ (print_expr pctx e)
+				let buf = Buffer.create 0 in
+				let interpolate () =
+					Codegen.interpolate_code pctx.pc_com code tl (Buffer.add_string buf) (fun e -> Buffer.add_string buf (print_expr pctx e)) ecode.epos
 				in
 				in
 				let old = pctx.pc_com.error in
 				let old = pctx.pc_com.error in
 				pctx.pc_com.error <- abort;
 				pctx.pc_com.error <- abort;
-				Std.finally (fun() -> pctx.pc_com.error <- old) (fun() -> Codegen.interpolate_code pctx.pc_com code tl f_string f_expr ecode.epos) ();
-				!r
+				Std.finally (fun() -> pctx.pc_com.error <- old) interpolate ();
+				Buffer.contents buf
 			| ("python_Syntax._pythonCode"), [e] ->
 			| ("python_Syntax._pythonCode"), [e] ->
 				print_expr pctx e
 				print_expr pctx e
 			| "python_Syntax._callNamedUntyped",el ->
 			| "python_Syntax._callNamedUntyped",el ->