Skip to content

Commit 4b80ac5

Browse files
committed
Avoid map_type_expr in common case
1 parent 5364163 commit 4b80ac5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

typing/jkind.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ let add_with_bounds ~modality ~type_expr t =
19201920
~relevant_for_nullability:`Irrelevant ~type_expr ~modality t.jkind
19211921
}
19221922

1923-
let has_with_bounds t =
1923+
let has_with_bounds (type r) (t : (_ * r) jkind) =
19241924
match t.jkind.with_bounds with
19251925
| No_with_bounds -> false
19261926
| With_bounds tys -> not (With_bounds_types.is_empty tys)
@@ -2932,7 +2932,10 @@ let round_up (type l r) ~jkind_of_type (t : (allowed * r) jkind) :
29322932
quality = Not_best (* As required by the fact that this is a [jkind_r] *)
29332933
}
29342934

2935-
let map_type_expr f t = { t with jkind = Jkind_desc.map_type_expr f t.jkind }
2935+
let map_type_expr f t =
2936+
if has_with_bounds t
2937+
then { t with jkind = Jkind_desc.map_type_expr f t.jkind }
2938+
else t (* short circuit this common case *)
29362939

29372940
(* this is hammered on; it must be fast! *)
29382941
let check_sub ~jkind_of_type sub super =

0 commit comments

Comments
 (0)