Skip to content

Commit 3e32220

Browse files
committed
tweak, remove use of Obj.magic
1 parent d827908 commit 3e32220

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

jscomp/runtime/caml_hash.ml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24-
24+
[@@@bs.config {flags = [|"-bs-noassertfalse"|]}]
2525
type 'a cell = {
2626
content : 'a ;
27-
mutable next : 'a cell_opt
27+
mutable next : 'a cell option
2828
}
29-
and 'a cell_opt = 'a cell option
3029
and 'a t = {
3130
mutable length : int ;
32-
mutable first : 'a cell_opt;
33-
mutable last : 'a cell_opt
31+
mutable first : 'a cell option;
32+
mutable last : 'a cell option
3433
}
3534

3635

@@ -56,23 +55,25 @@ let push_back (q :'a t) (v : 'a) =
5655
last . next <- cell;
5756
q . last <- cell
5857

59-
let is_empty_queue q = q . length = 0
58+
let is_empty_queue q = q.length = 0
6059

6160
(* pop from front *)
6261

6362

6463
let unsafe_pop (q : 'a t) =
65-
let cell = (Obj.magic (q . first) : 'a cell) in
66-
let next =cell.next in
67-
if next = None then (
68-
q . length <- 0 ;
69-
q . first <- None;
70-
q . last<- None;
71-
) else (
72-
q . length <- q . length - 1;
73-
q . first <- next;
74-
);
75-
cell.content
64+
match q.first with
65+
| None -> assert false
66+
| Some cell ->
67+
let next =cell.next in
68+
if next = None then (
69+
q . length <- 0 ;
70+
q . first <- None;
71+
q . last<- None;
72+
) else (
73+
q . length <- q . length - 1;
74+
q . first <- next;
75+
);
76+
cell.content
7677

7778

7879

0 commit comments

Comments
 (0)