Skip to content

Commit da928db

Browse files
author
Cristiano Calcagno
committed
js versions for comparison
1 parent dfdf52f commit da928db

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

jscomp/runtime/caml_obj.ml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,29 @@ and aux_obj_compare (a: Obj.t) (b: Obj.t) =
258258
| None, (Some _) -> 1
259259
| (Some x), (Some y) -> compare x y in
260260
res
261+
(*
262+
and aux_obj_compare (a: Obj.t) (b: Obj.t) : int = [%bs.raw {|
263+
function (a, b) {
264+
var min_key_lhs;
265+
var min_key_rhs;
266+
for (var key in a) {
267+
if (!b.hasOwnProperty(key) || caml_compare(a[key], b[key]) > 0) {
268+
if (!min_key_rhs || key < min_key_rhs) { min_key_rhs = key }
269+
}
270+
}
271+
for (var key in b) {
272+
if (!a.hasOwnProperty(key) || caml_compare(b[key], a[key]) > 0) {
273+
if (!min_key_lhs || key < min_key_lhs) { min_key_lhs = key }
274+
}
275+
}
276+
if (!min_key_lhs) { return !min_key_rhs ? 0 : 1}
277+
if (!min_key_rhs) { return -1 }
278+
return min_key_lhs < min_key_rhs ? -1 : 1
279+
}
280+
|}]
281+
a b [@bs]
282+
*)
283+
261284

262285
type eq = Obj.t -> Obj.t -> bool
263286

@@ -325,6 +348,24 @@ and aux_obj_equal (a: Obj.t) (b: Obj.t) =
325348
O.for_in a do_key_a [@bs];
326349
if !result then O.for_in b do_key_b [@bs];
327350
!result
351+
(*
352+
and aux_obj_equal (a: Obj.t) (b: Obj.t) : bool = [%bs.raw {|
353+
function (a, b) {
354+
for (var key in a) {
355+
if (!b.hasOwnProperty(key)) {
356+
return false
357+
}
358+
}
359+
for (var key in b) {
360+
if (!a.hasOwnProperty(key) || !caml_equal(a[key], b[key])) {
361+
return false
362+
}
363+
}
364+
return true
365+
}
366+
|}]
367+
a b [@bs]
368+
*)
328369

329370
let caml_equal_null (x : Obj.t) (y : Obj.t Js.null) =
330371
match Js.nullToOption y with

0 commit comments

Comments
 (0)