Skip to content

Commit c5ab3cf

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

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
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 fromString(radix, x) {
@@ -50,19 +48,9 @@ function range(start, end) {
5048
}
5149

5250
function clamp(min, max, value) {
53-
var value$1;
54-
if (max !== undefined) {
55-
var max$1 = Caml_option.valFromOption(max);
56-
value$1 = Caml_obj.lessthan(max$1, value) ? max$1 : value;
57-
} else {
58-
value$1 = value;
59-
}
60-
if (min === undefined) {
61-
return value$1;
62-
}
63-
var min$1 = Caml_option.valFromOption(min);
64-
if (Caml_obj.greaterthan(min$1, value$1)) {
65-
return min$1;
51+
var value$1 = max !== undefined && max < value ? max : value;
52+
if (min !== undefined && min > value$1) {
53+
return min;
6654
} else {
6755
return value$1;
6856
}

src/Core__Int.res

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

6363
let range = (start, end) => rangeWithOptions(start, end, {})
6464

65-
let clamp = (~min=?, ~max=?, value) => {
65+
let clamp = (~min=?, ~max=?, value): int => {
6666
let value = switch max {
6767
| Some(max) if max < value => max
6868
| _ => value

test/TestSuite.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ var Concurrently = PromiseTest.Concurrently;
2424

2525
var panicTest = ErrorTests.panicTest;
2626

27-
var eq = FloatTests.eq;
28-
2927
var $$catch = IntTests.$$catch;
3028

29+
var eq = FloatTests.eq;
30+
3131
export {
3232
TestError ,
3333
fail ,
@@ -38,7 +38,7 @@ export {
3838
Catching ,
3939
Concurrently ,
4040
panicTest ,
41-
eq ,
4241
$$catch ,
42+
eq ,
4343
}
4444
/* IntTests Not a pure module */

0 commit comments

Comments
 (0)