Skip to content

Commit 58f81b7

Browse files
committed
refactor: intern all atoms
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent cb060a4 commit 58f81b7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/dune_sexp/atom.ml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@ let is_valid =
3535
len > 0 && loop s 0 len
3636
;;
3737

38+
let table = String.Table.create 512
39+
40+
let make s =
41+
match String.Table.find table s with
42+
| Some s -> s
43+
| None ->
44+
String.Table.add_exn table s s;
45+
s
46+
;;
47+
3848
let of_string s =
3949
if is_valid s
40-
then A s
50+
then A (make s)
4151
else Code_error.raise "Dune_lang.Atom.of_string got invalid atom" [ "atom", String s ]
4252
;;
4353

4454
let to_string (A s) = s
45-
let parse s = if is_valid s then Some (A s) else None
46-
let of_int i = A (string_of_int i)
55+
let parse s = if is_valid s then Some (A (make s)) else None
56+
let of_int i = A (make (string_of_int i))
4757
let of_float x = of_string (string_of_float x)
48-
let of_bool x = A (string_of_bool x)
58+
let of_bool x = A (make (string_of_bool x))
4959
let of_int64 i = A (Int64.to_string i)

0 commit comments

Comments
 (0)