Skip to content

Commit df325b2

Browse files
committed
More Lambda inlines
1 parent 7eb37d5 commit df325b2

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

src/typing/nullSafety.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,10 +1445,15 @@ class expr_checker mode immediate_execution report =
14451445
Check if specified expressions can be passed to a call which expects `types`.
14461446
*)
14471447
method private check_args callee args types =
1448+
let rec expr_with_unsafe_meta e =
1449+
match e.eexpr with
1450+
| TMeta ((Meta.NullSafety, [(EConst (Ident "Off"), _)], _), e) -> true
1451+
| TParenthesis e -> expr_with_unsafe_meta e
1452+
| _ -> false in
14481453
let rec traverse arg_num args types meta =
14491454
match (args, types, meta) with
14501455
| (arg :: args, (arg_name, optional, t) :: types, arg_meta :: meta) ->
1451-
let unsafe_argument = contains_unsafe_meta arg_meta in
1456+
let unsafe_argument = contains_unsafe_meta arg_meta || expr_with_unsafe_meta arg in
14521457
if
14531458
not optional && not unsafe_argument
14541459
&& not (self#can_pass_expr arg t arg.epos)

std/Lambda.hx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,14 @@ class Lambda {
122122
123123
If `f` is null, the result is unspecified.
124124
**/
125-
public static function exists<A>(it:Iterable<A>, f:(item:A) -> Bool) {
125+
public static inline function exists<A>(it:Iterable<A>, f:(item:A) -> Bool) {
126+
var isExists = false;
126127
for (x in it)
127-
if (f(x))
128-
return true;
129-
return false;
128+
if (f(x)) {
129+
isExists = true;
130+
break;
131+
}
132+
return isExists;
130133
}
131134

132135
/**
@@ -141,19 +144,22 @@ class Lambda {
141144
142145
If `f` is null, the result is unspecified.
143146
**/
144-
public static function foreach<A>(it:Iterable<A>, f:(item:A) -> Bool) {
147+
public static inline function foreach<A>(it:Iterable<A>, f:(item:A) -> Bool) {
148+
var isAll = true;
145149
for (x in it)
146-
if (!f(x))
147-
return false;
148-
return true;
150+
if (!f(x)) {
151+
isAll = false;
152+
break;
153+
}
154+
return isAll;
149155
}
150156

151157
/**
152158
Calls `f` on all elements of `it`, in order.
153159
154160
If `f` is null, the result is unspecified.
155161
**/
156-
public static function iter<A>(it:Iterable<A>, f:(item:A) -> Void) {
162+
public static inline function iter<A>(it:Iterable<A>, f:(item:A) -> Void) {
157163
for (x in it)
158164
f(x);
159165
}
@@ -164,7 +170,7 @@ class Lambda {
164170
If `it` is empty, the result is the empty Array even if `f` is null.
165171
Otherwise if `f` is null, the result is unspecified.
166172
**/
167-
public static function filter<A>(it:Iterable<A>, f:(item:A) -> Bool) {
173+
public static inline function filter<A>(it:Iterable<A>, f:(item:A) -> Bool) {
168174
return [for (x in it) if (f(x)) x];
169175
}
170176

@@ -180,7 +186,7 @@ class Lambda {
180186
181187
If `it` or `f` are null, the result is unspecified.
182188
**/
183-
public static function fold<A, B>(it:Iterable<A>, f:(item:A, result:B) -> B, first:B):B {
189+
public static inline function fold<A, B>(it:Iterable<A>, f:(item:A, result:B) -> B, first:B):B {
184190
for (x in it)
185191
first = f(x, first);
186192
return first;
@@ -191,7 +197,7 @@ class Lambda {
191197
192198
If `it` or `f` are null, the result is unspecified.
193199
**/
194-
public static function foldi<A, B>(it:Iterable<A>, f:(item:A, result:B, index:Int) -> B, first:B):B {
200+
public static inline function foldi<A, B>(it:Iterable<A>, f:(item:A, result:B, index:Int) -> B, first:B):B {
195201
var i = 0;
196202
for (x in it) {
197203
first = f(x, first, i);
@@ -206,7 +212,7 @@ class Lambda {
206212
207213
This function traverses all elements.
208214
**/
209-
public static function count<A>(it:Iterable<A>, ?pred:(item:A) -> Bool) {
215+
public static inline function count<A>(it:Iterable<A>, ?pred:(item:A) -> Bool) {
210216
var n = 0;
211217
if (pred == null)
212218
for (_ in it)
@@ -252,12 +258,15 @@ class Lambda {
252258
253259
If `f` is null, the result is unspecified.
254260
**/
255-
public static function find<T>(it:Iterable<T>, f:(item:T) -> Bool):Null<T> {
261+
public static inline function find<T>(it:Iterable<T>, f:(item:T) -> Bool):Null<T> {
262+
var first:Null<T> = null;
256263
for (v in it) {
257-
if (f(v))
258-
return v;
264+
if (f(@:nullSafety(Off) v)) {
265+
first = v;
266+
break;
267+
}
259268
}
260-
return null;
269+
return first;
261270
}
262271

263272
/**

0 commit comments

Comments
 (0)