Skip to content

Commit ddd61be

Browse files
committed
Str: use a domain local value to store the global state
1 parent 824e9e8 commit ddd61be

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/str.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ let compile_regexp s c =
3636
}
3737
;;
3838

39-
let state = ref None
39+
let state = Domain.DLS.new_key (fun () -> None)
4040

4141
let string_match re s p =
4242
match exec ~pos:p (Lazy.force re.mtch) s with
4343
| res ->
44-
state := Some res;
44+
Domain.DLS.set state (Some res);
4545
true
4646
| exception Not_found ->
47-
state := None;
47+
Domain.DLS.set state None;
4848
false
4949
;;
5050

@@ -58,34 +58,34 @@ let string_partial_match re s p =
5858
let search_forward re s p =
5959
match exec ~pos:p (Lazy.force re.srch) s with
6060
| res ->
61-
state := Some res;
61+
Domain.DLS.set state (Some res);
6262
fst (Group.offset res 0)
6363
| exception Not_found ->
64-
state := None;
64+
Domain.DLS.set state None;
6565
raise Not_found
6666
;;
6767

6868
let rec search_backward re s p =
6969
match exec ~pos:p (Lazy.force re.mtch) s with
7070
| res ->
71-
state := Some res;
71+
Domain.DLS.set state (Some res);
7272
p
7373
| exception Not_found ->
74-
state := None;
74+
Domain.DLS.set state None;
7575
if p = 0 then raise Not_found else search_backward re s (p - 1)
7676
;;
7777

7878
let valid_group n =
7979
n >= 0
8080
&& n < 10
8181
&&
82-
match !state with
82+
match Domain.DLS.get state with
8383
| None -> false
8484
| Some m -> n < Group.nb_groups m
8585
;;
8686

8787
let offset_group i =
88-
match !state with
88+
match Domain.DLS.get state with
8989
| Some m -> Group.offset m i
9090
| None -> raise Not_found
9191
;;

0 commit comments

Comments
 (0)