Skip to content

Commit 0ff222c

Browse files
authored
Small optimisation for caml_modify (#1226)
1 parent 3f50ccc commit 0ff222c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ocaml/runtime/memory.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,17 @@ CAMLexport CAMLweakdef void caml_modify (value *fp, value val)
671671
if (Is_young(old)) return;
672672
/* Here, [old] can be a pointer within the major heap.
673673
Check for condition 2. */
674-
if (caml_gc_phase == Phase_mark) caml_darken(old, NULL);
674+
if (caml_gc_phase == Phase_mark) {
675+
header_t hd = Hd_val(old);
676+
if (Tag_hd (hd) == Infix_tag) {
677+
/* Infix_tag is always Caml_white */
678+
CAMLassert(Is_white_hd(hd));
679+
}
680+
/* Inline the white-header check, to save a pagetable lookup */
681+
if (Is_white_hd(hd)) {
682+
caml_darken(old, NULL);
683+
}
684+
}
675685
}
676686
/* Check for condition 1. */
677687
if (Is_block(val) && Is_young(val)) {

0 commit comments

Comments
 (0)