haxe
haxe copied to clipboard
[hxb] Shared string pools
At the moment, every hxb module comes with its own string pool in the STR chunk. This is nice for having self-contained modules, but duplicates quite a bit of raw data. I'd like to look into allowing external string pools:
--hxbcould generate one big string pool at the archive root.--hxb-libwould then read that and pass it to the individual readers.- The server could persist its own string pool without the need to encode/decode anything.
One challenge for the latter is that the writer uses DynArray, while the reader wants to make lookups into an array. I'd like to keep this because it's the fastest lookup possible, but that means we need a way to go from DynArray to array. This is O(n) in the official implementation:
let to_array d =
if d.len = 0 then begin
(* since the empty array is an atom, we don't care if float or not *)
[||]
end else begin
let arr = Array.make d.len (iget d.arr 0) in
for i = 1 to d.len - 1 do
Array.unsafe_set arr i (iget d.arr i)
done;
arr;
end
I was hoping that the internal structure of DynArray would be array and we could just unsafely use that (we don't care about additional trailing arguments for this use-case), but unfortunately it's some external 'a intern thing. I'd even be willing to make the reader use that directly, but extlib hides this type and its API. So I suppose we need our own dynamic array implementation for this particular situation.