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

Inline Array.exists (#12981)

上级 2c71da39
...@@ -111,7 +111,7 @@ namespace Microsoft.FSharp.Collections ...@@ -111,7 +111,7 @@ namespace Microsoft.FSharp.Collections
arr arr
[<CompiledName("Collect")>] [<CompiledName("Collect")>]
let collect (mapping: 'T -> 'U[]) (array: 'T[]) : 'U[]= let collect (mapping: 'T -> 'U[]) (array: 'T[]) : 'U[]=
checkNonNull "array" array checkNonNull "array" array
let len = array.Length let len = array.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked<'U[]> len let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked<'U[]> len
...@@ -362,11 +362,14 @@ namespace Microsoft.FSharp.Collections ...@@ -362,11 +362,14 @@ namespace Microsoft.FSharp.Collections
Microsoft.FSharp.Primitives.Basics.Array.mapFoldBack mapping array state Microsoft.FSharp.Primitives.Basics.Array.mapFoldBack mapping array state
[<CompiledName("Exists")>] [<CompiledName("Exists")>]
let exists (predicate: 'T -> bool) (array: 'T[]) = let inline exists ([<InlineIfLambda>] predicate: 'T -> bool) (array: 'T[]) =
checkNonNull "array" array checkNonNull "array" array
let len = array.Length let mutable state = false
let rec loop i = i < len && (predicate array.[i] || loop (i+1)) let mutable i = 0
len > 0 && loop 0 while not state && i < array.Length do
state <- predicate array.[i]
i <- i + 1
state
[<CompiledName("Contains")>] [<CompiledName("Contains")>]
let inline contains value (array: 'T[]) = let inline contains value (array: 'T[]) =
......
...@@ -769,7 +769,7 @@ module Array = ...@@ -769,7 +769,7 @@ module Array =
/// Evaluates to <c>false</c> /// Evaluates to <c>false</c>
/// </example> /// </example>
[<CompiledName("Exists")>] [<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> /// <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.
先完成此消息的编辑!
想要评论请 注册