mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
feat: improve task local storage
This commit is contained in:
parent
41b73462dd
commit
e8e61f6b30
1 changed files with 5 additions and 2 deletions
|
|
@ -20,8 +20,11 @@ type ls_value += Dummy
|
|||
|
||||
(** Resize array of TLS values *)
|
||||
let[@inline never] resize_ (cur : ls_value array ref) n =
|
||||
if n > Sys.max_array_length then failwith "too many task local storage keys";
|
||||
let len = Array.length !cur in
|
||||
let new_ls = Array.make (max n ((len * 2) + 2)) Dummy in
|
||||
let new_ls =
|
||||
Array.make (min Sys.max_array_length (max n ((len * 2) + 2))) Dummy
|
||||
in
|
||||
Array.blit !cur 0 new_ls 0 len;
|
||||
cur := new_ls
|
||||
|
||||
|
|
@ -32,7 +35,7 @@ let[@inline] get_cur_ () : ls_value array ref =
|
|||
|
||||
let get (type a) ((module K) : a key) : a =
|
||||
let cur = get_cur_ () in
|
||||
if K.offset >= Array.length !cur then resize_ cur K.offset;
|
||||
if K.offset >= Array.length !cur then resize_ cur (K.offset + 1);
|
||||
match !cur.(K.offset) with
|
||||
| K.V x -> (* common case first *) x
|
||||
| Dummy ->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue