未验证 提交 8b67124f 编写于 作者: P Pierre Irrmann 提交者: GitHub

Inline Array.exists (#12981)

上级 2c71da39
......@@ -111,7 +111,7 @@ namespace Microsoft.FSharp.Collections
arr
[<CompiledName("Collect")>]
let collect (mapping: 'T -> 'U[]) (array: 'T[]) : 'U[]=
let collect (mapping: 'T -> 'U[]) (array: 'T[]) : 'U[]=
checkNonNull "array" array
let len = array.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked<'U[]> len
......@@ -362,11 +362,14 @@ namespace Microsoft.FSharp.Collections
Microsoft.FSharp.Primitives.Basics.Array.mapFoldBack mapping array state
[<CompiledName("Exists")>]
let exists (predicate: 'T -> bool) (array: 'T[]) =
let inline exists ([<InlineIfLambda>] predicate: 'T -> bool) (array: 'T[]) =
checkNonNull "array" array
let len = array.Length
let rec loop i = i < len && (predicate array.[i] || loop (i+1))
len > 0 && loop 0
let mutable state = false
let mutable i = 0
while not state && i < array.Length do
state <- predicate array.[i]
i <- i + 1
state
[<CompiledName("Contains")>]
let inline contains value (array: 'T[]) =
......
......@@ -769,7 +769,7 @@ module Array =
/// Evaluates to <c>false</c>
/// </example>
[<CompiledName("Exists")>]
val exists: predicate:('T -> bool) -> array:'T[] -> bool
val inline exists: predicate:('T -> bool) -> array:'T[] -> bool
/// <summary>Tests if any pair of corresponding elements of the arrays satisfies the given predicate.</summary>
///
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册