Skip to content

Commit

Permalink
avoid write_list for anon fields too
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Simn committed Jan 18, 2024
1 parent 5e91041 commit 71169d6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 71169d6

Please sign in to comment.