Explorar o código

avoid write_list for anon fields too

Folding a PMap to a list only to then get its length (which is a linear operation) and iterate over it isn't the power move that I thought it was.
Simon Krajewski hai 1 ano
pai
achega
71169d6312
Modificáronse 1 ficheiros con 9 adicións e 3 borrados
  1. 9 3
      src/compiler/hxb/hxbWriter.ml

+ 9 - 3
src/compiler/hxb/hxbWriter.ml

@@ -1015,9 +1015,15 @@ module HxbWriter = struct
 
 	let rec write_anon writer (an : tanon) (ttp : type_params) =
 		let write_fields () =
-			Chunk.write_list writer.chunk (PMap.foldi (fun s f acc -> (s,f) :: acc) an.a_fields []) (fun (_,cf) ->
-				write_anon_field_ref writer cf
-			)
+			let restore = start_temporary_chunk writer 256 in
+			let i = ref 0 in
+			PMap.iter (fun _ cf ->
+				write_anon_field_ref writer cf;
+				incr i;
+			) an.a_fields;
+			let bytes = restore (fun new_chunk -> Chunk.get_bytes new_chunk) in
+			Chunk.write_uleb128 writer.chunk !i;
+			Chunk.write_bytes writer.chunk bytes;
 		in
 		begin match !(an.a_status) with
 		| Closed ->