Skip to content

Commit a338988

Browse files
committed
refactor(int/clamp): adding type annotation allows compiler to inline primitives
1 parent bc4a552 commit a338988

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/Core__Int.mjs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
4-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
53

64
function fromString(radix, x) {
75
var maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x);
@@ -13,19 +11,9 @@ function fromString(radix, x) {
1311
}
1412

1513
function clamp(min, max, value) {
16-
var value$1;
17-
if (max !== undefined) {
18-
var max$1 = Caml_option.valFromOption(max);
19-
value$1 = Caml_obj.lessthan(max$1, value) ? max$1 : value;
20-
} else {
21-
value$1 = value;
22-
}
23-
if (min === undefined) {
24-
return value$1;
25-
}
26-
var min$1 = Caml_option.valFromOption(min);
27-
if (Caml_obj.greaterthan(min$1, value$1)) {
28-
return min$1;
14+
var value$1 = max !== undefined && max < value ? max : value;
15+
if (min !== undefined && min > value$1) {
16+
return min;
2917
} else {
3018
return value$1;
3119
}

src/Core__Int.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let fromString = (~radix=?, x) => {
3636

3737
external mod: (int, int) => int = "%modint"
3838

39-
let clamp = (~min=?, ~max=?, value) => {
39+
let clamp = (~min=?, ~max=?, value): int => {
4040
let value = switch max {
4141
| Some(max) if max < value => max
4242
| _ => value

0 commit comments

Comments
 (0)