浏览代码

[lua] Anon creation is done inplace, the basic idea is that LuaJIT caches anonimous objects constructors. That is, just copies couple of bytes to the memory instead of full initialization. Original solution also involved too much overhead by itself.

peyty 9 年之前
父节点
当前提交
27d4b5f511
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      genlua.ml

+ 5 - 3
genlua.ml

@@ -685,9 +685,11 @@ and gen_expr ?(local=true) ctx e = begin
 		spr ctx "_hx_empty()";
 		spr ctx "_hx_empty()";
 		ctx.separator <- true
 		ctx.separator <- true
 	| TObjectDecl fields ->
 	| TObjectDecl fields ->
-		spr ctx "_hx_anon(";
-		concat ctx ", " (fun (f,e) -> print ctx "\"%s\", " f; gen_value ctx e) fields;
-		spr ctx ")";
+		spr ctx "setmetatable({__fields__={";
+		concat ctx "," (fun (f,e) -> print ctx "%s=" (anon_field f); spr ctx "true") fields;
+		spr ctx "},";
+		concat ctx "," (fun (f,e) -> print ctx "%s=" (anon_field f); gen_value ctx e) fields;
+		spr ctx "},{__newindex=_hx_anon_newindex})";
 		ctx.separator <- true
 		ctx.separator <- true
 	| TFor (v,it,e) ->
 	| TFor (v,it,e) ->
 		let handle_break = handle_break ctx e in
 		let handle_break = handle_break ctx e in