Skip to content

Commit 6980539

Browse files
committed
tweak to reduce the usage of Obj.field
1 parent e180e35 commit 6980539

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

jscomp/runtime/caml_obj.ml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,32 +218,33 @@ let rec caml_compare (a : Obj.t) (b : Obj.t) : int =
218218
let len_a = Obj.size a in
219219
let len_b = Obj.size b in
220220
if len_a = len_b then
221-
if O.isArray(a)
222-
then aux_same_length a b 0 len_a
221+
if O.isArray a
222+
then aux_same_length (Obj.magic a : Obj.t array ) (Obj.magic b : Obj.t array) 0 len_a
223223
else if [%raw{|a instanceof Date && b instanceof Date|}] then
224224
[%raw{|a - b|}]
225225
else aux_obj_compare a b
226226
else if len_a < len_b then
227-
aux_length_a_short a b 0 len_a
227+
(* at least one is not zero, so it is an array block*)
228+
aux_length_a_short (Obj.magic a : Obj.t array) (Obj.magic b : Obj.t array) 0 len_a
228229
else
229-
aux_length_b_short a b 0 len_b
230-
and aux_same_length (a : Obj.t) (b : Obj.t) i same_length =
230+
aux_length_b_short (Obj.magic a : Obj.t array) (Obj.magic b : Obj.t array) 0 len_b
231+
and aux_same_length (a : Obj.t array) (b : Obj.t array) i same_length =
231232
if i = same_length then
232233
0
233234
else
234-
let res = caml_compare (Obj.field a i) (Obj.field b i) in
235+
let res = caml_compare (Caml_array_extern.unsafe_get a i) (Caml_array_extern.unsafe_get b i) in
235236
if res <> 0 then res
236237
else aux_same_length a b (i + 1) same_length
237-
and aux_length_a_short (a : Obj.t) (b : Obj.t) i short_length =
238+
and aux_length_a_short (a : Obj.t array) (b : Obj.t array) i short_length =
238239
if i = short_length then -1
239240
else
240-
let res = caml_compare (Obj.field a i) (Obj.field b i) in
241+
let res = caml_compare (Caml_array_extern.unsafe_get a i) (Caml_array_extern.unsafe_get b i) in
241242
if res <> 0 then res
242243
else aux_length_a_short a b (i+1) short_length
243-
and aux_length_b_short (a : Obj.t) (b : Obj.t) i short_length =
244+
and aux_length_b_short (a : Obj.t array) (b : Obj.t array) i short_length =
244245
if i = short_length then 1
245246
else
246-
let res = caml_compare (Obj.field a i) (Obj.field b i) in
247+
let res = caml_compare (Caml_array_extern.unsafe_get a i) (Caml_array_extern.unsafe_get b i) in
247248
if res <> 0 then res
248249
else aux_length_b_short a b (i+1) short_length
249250
and aux_obj_compare (a: Obj.t) (b: Obj.t) =

0 commit comments

Comments
 (0)