Skip to content

Commit 911bcf3

Browse files
glennslzth
authored andcommitted
refactor(int/clamp): adding type annotation allows compiler to inline primitives
1 parent 08c8a26 commit 911bcf3

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/Core__Int.mjs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
43
import * as Pervasives from "rescript/lib/es6/pervasives.js";
5-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
64
import * as Core__Array from "./Core__Array.mjs";
75

86
function equal(a, b) {
@@ -64,19 +62,9 @@ function range(start, end) {
6462
}
6563

6664
function clamp(min, max, value) {
67-
var value$1;
68-
if (max !== undefined) {
69-
var max$1 = Caml_option.valFromOption(max);
70-
value$1 = Caml_obj.lessthan(max$1, value) ? max$1 : value;
71-
} else {
72-
value$1 = value;
73-
}
74-
if (min === undefined) {
75-
return value$1;
76-
}
77-
var min$1 = Caml_option.valFromOption(min);
78-
if (Caml_obj.greaterthan(min$1, value$1)) {
79-
return min$1;
65+
var value$1 = max !== undefined && max < value ? max : value;
66+
if (min !== undefined && min > value$1) {
67+
return min;
8068
} else {
8169
return value$1;
8270
}

src/Core__Int.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ let rangeWithOptions = (start, end, options) => {
6767

6868
let range = (start, end) => rangeWithOptions(start, end, {})
6969

70-
let clamp = (~min=?, ~max=?, value) => {
70+
let clamp = (~min=?, ~max=?, value): int => {
7171
let value = switch max {
7272
| Some(max) if max < value => max
7373
| _ => value

0 commit comments

Comments
 (0)