Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions src/fsharp/FSharp.Core/array.fs
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,22 +86,21 @@ namespace Microsoft.FSharp.Collections
[<CompiledName("CopyTo")>]
let inline blit (source : 'T[]) (sourceIndex:int) (target: 'T[]) (targetIndex:int) (count:int) =
Array.Copy(source, sourceIndex, target, targetIndex, count)

let rec concatAddLengths (arrs:'T[][]) i acc =
if i >= arrs.Length then acc
else concatAddLengths arrs (i+1) (acc + arrs.[i].Length)

let rec concatBlit (arrs:'T[][]) i j (tgt:'T[]) =
if i < arrs.Length then
let h = arrs.[i]
let len = h.Length
Array.Copy(h, 0, tgt, j, len)
concatBlit arrs (i+1) (j+len) tgt

let concatArrays (arrs : 'T[][]) : 'T[] =
let mutable acc = 0
for h in arrs do
acc <- acc + h.Length

let res = Array.zeroCreateUnchecked acc

let concatArrays (arrs : 'T[][]) =
let res = Array.zeroCreateUnchecked (concatAddLengths arrs 0 0)
concatBlit arrs 0 0 res
res
let mutable j = 0
for i = 0 to arrs.Length-1 do
let h = arrs.[i]
let len = h.Length
Array.Copy(h,0,res,j,len)
j <- j + len
res

[<CompiledName("Concat")>]
let concat (arrays: seq<'T[]>) =
Expand DownExpand Up@@ -1001,22 +1000,26 @@ namespace Microsoft.FSharp.Collections
let inline compareWith (comparer:'T -> 'T -> int) (array1: 'T[]) (array2: 'T[]) =
checkNonNull "array1" array1
checkNonNull "array2" array2

let length1 = array1.Length
let length2 = array2.Length
let minLength = Operators.min length1 length2

let rec loop index =
if index = minLength then
if length1 = length2 then 0
elif length1 < length2 then -1
else 1
else
let result = comparer array1.[index] array2.[index]
if result <> 0 then result else
loop (index+1)

let mutable i = 0
let mutable result = 0

if length1 < length2 then
while i < array1.Length && result = 0 do
result <- comparer array1.[i] array2.[i]
i <- i + 1
else
while i < array2.Length && result = 0 do
result <- comparer array1.[i] array2.[i]
i <- i + 1

loop 0
if result <> 0 then result
elif length1 = length2 then 0
elif length1 < length2 then -1
else 1

[<CompiledName("GetSubArray")>]
let sub (array:'T[]) (startIndex:int) (count:int) =
Expand Down