Skip to content

Commit 2a4dc9c

Browse files
authored
Merge pull request #1345 from forki/blittest
Changing Array.blit to be just an alias for Array.Copy
2 parents 1e9ccfd + 2b8da0c commit 2a4dc9c

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

src/absil/ilsupp.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ type ResFormatNode(tid:int32, nid:int32, lid:int32, dataOffset:int32, pbLinkedRe
535535
let SaveChunk(p : byte[], sz : int) =
536536
if Unchecked.defaultof<byte[]> <> pUnlinkedResource then
537537
Bytes.blit p 0 pUnlinkedResource (!unlinkedResourceOffset + offset) sz
538-
unlinkedResourceOffset := !unlinkedResourceOffset + sz ;
539-
size := !size + sz ;
538+
unlinkedResourceOffset := !unlinkedResourceOffset + sz
539+
size := !size + sz
540540

541541
()
542542

@@ -846,10 +846,10 @@ let unlinkResource (ulLinkedResourceBaseRVA:int32) (pbLinkedResource:byte[]) =
846846
let rfh = ResFormatHeader()
847847
let rfhBytes = rfh.toBytes()
848848
Bytes.blit rfhBytes 0 pResBuffer 0 ResFormatHeader.Width
849-
resBufferOffset <- resBufferOffset + ResFormatHeader.Width ;
849+
resBufferOffset <- resBufferOffset + ResFormatHeader.Width
850850

851851
for i = 0 to (nResNodes - 1) do
852-
resBufferOffset <- resBufferOffset + pResNodes.[i].Save(ulLinkedResourceBaseRVA, pbLinkedResource, pResBuffer, resBufferOffset) ;
852+
resBufferOffset <- resBufferOffset + pResNodes.[i].Save(ulLinkedResourceBaseRVA, pbLinkedResource, pResBuffer, resBufferOffset)
853853

854854
pResBuffer
855855
#endif

src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ArrayProperties.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open System
66
open System.Collections.Generic
77
open NUnit.Framework
88
open FsCheck
9+
open Utils
910

1011
let isStable sorted = sorted |> Seq.pairwise |> Seq.forall (fun ((ia, a),(ib, b)) -> if a = b then ia < ib else true)
1112

@@ -15,6 +16,18 @@ let distinctByStable<'a when 'a : comparison> (xs : 'a []) =
1516
isStable sorted
1617

1718
[<Test>]
18-
let ``Seq.distinctBy is stable`` () =
19+
let ``Array.distinctBy is stable`` () =
1920
Check.QuickThrowOnFailure distinctByStable<int>
2021
Check.QuickThrowOnFailure distinctByStable<string>
22+
23+
let blitWorksLikeCopy<'a when 'a : comparison> (source : 'a [], sourceIndex, target : 'a [], targetIndex, count) =
24+
let target1 = Array.copy target
25+
let target2 = Array.copy target
26+
let a = runAndCheckIfAnyError (fun () -> Array.blit source sourceIndex target1 targetIndex count)
27+
let b = runAndCheckIfAnyError (fun () -> Array.Copy(source, sourceIndex, target2, targetIndex, count))
28+
a = b && target1 = target2
29+
30+
[<Test>]
31+
let ``Array.blit works like Array.Copy`` () =
32+
Check.QuickThrowOnFailure blitWorksLikeCopy<int>
33+
Check.QuickThrowOnFailure blitWorksLikeCopy<string>

src/fsharp/FSharp.Core/array.fs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,8 @@ namespace Microsoft.FSharp.Collections
8383

8484
[<CodeAnalysis.SuppressMessage("Microsoft.Naming","CA1704:IdentifiersShouldBeSpelledCorrectly")>]
8585
[<CompiledName("CopyTo")>]
86-
let blit (source : 'T[]) sourceIndex (target: 'T[]) targetIndex count =
87-
checkNonNull "source" source
88-
checkNonNull "target" target
89-
if sourceIndex < 0 then invalidArg "sourceIndex" (SR.GetString(SR.inputMustBeNonNegative))
90-
if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
91-
if targetIndex < 0 then invalidArg "targetIndex" (SR.GetString(SR.inputMustBeNonNegative))
92-
if sourceIndex + count > source.Length then invalidArg "count" (SR.GetString(SR.outOfRange))
93-
if targetIndex + count > target.Length then invalidArg "count" (SR.GetString(SR.outOfRange))
86+
let inline blit (source : 'T[]) (sourceIndex:int) (target: 'T[]) (targetIndex:int) (count:int) =
9487
Array.Copy(source, sourceIndex, target, targetIndex, count)
95-
// for i = 0 to count - 1 do
96-
// target.[targetIndex+i] <- source.[sourceIndex + i]
9788

9889
let rec concatAddLengths (arrs:'T[][]) i acc =
9990
if i >= arrs.Length then acc

src/fsharp/FSharp.Core/array.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace Microsoft.FSharp.Collections
6262
/// <exception cref="System.ArgumentException">Thrown when any of sourceIndex, targetIndex or count are negative,
6363
/// or when there aren't enough elements in source or target.</exception>
6464
[<CompiledName("CopyTo")>]
65-
val blit: source:'T[] -> sourceIndex:int -> target:'T[] -> targetIndex:int -> count:int -> unit
65+
val inline blit: source:'T[] -> sourceIndex:int -> target:'T[] -> targetIndex:int -> count:int -> unit
6666

6767
/// <summary>For each element of the array, applies the given function. Concatenates all the results and return the combined array.</summary>
6868
/// <param name="mapping">The function to create sub-arrays from the input array elements.</param>

src/utils/prim-lexing.fs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,27 @@ namespace Internal.Utilities.Text.Lexing
7474
and [<Sealed>]
7575
internal LexBuffer<'Char>(filler: LexBufferFiller<'Char>) =
7676
let context = new Dictionary<string,obj>(1)
77-
let mutable buffer=[||];
77+
let mutable buffer = [||]
7878
/// number of valid characters beyond bufferScanStart.
79-
let mutable bufferMaxScanLength=0;
79+
let mutable bufferMaxScanLength = 0
8080
/// count into the buffer when scanning.
81-
let mutable bufferScanStart=0;
81+
let mutable bufferScanStart = 0
8282
/// number of characters scanned so far.
83-
let mutable bufferScanLength=0;
83+
let mutable bufferScanLength = 0
8484
/// length of the scan at the last accepting state.
85-
let mutable lexemeLength=0;
85+
let mutable lexemeLength = 0
8686
/// action related to the last accepting state.
87-
let mutable bufferAcceptAction=0;
88-
let mutable eof = false;
89-
let mutable startPos = Position.Empty ;
87+
let mutable bufferAcceptAction = 0
88+
let mutable eof = false
89+
let mutable startPos = Position.Empty
9090
let mutable endPos = Position.Empty
9191

92-
// Throw away all the input besides the lexeme
93-
92+
// Throw away all the input besides the lexeme
9493
let discardInput () =
9594
let keep = Array.sub buffer bufferScanStart bufferScanLength
9695
let nkeep = keep.Length
97-
Array.blit keep 0 buffer 0 nkeep;
98-
bufferScanStart <- 0;
96+
Array.blit keep 0 buffer 0 nkeep
97+
bufferScanStart <- 0
9998
bufferMaxScanLength <- nkeep
10099

101100

@@ -142,7 +141,7 @@ namespace Internal.Utilities.Text.Lexing
142141
member lexbuf.EnsureBufferSize n =
143142
if lexbuf.BufferScanPos + n >= buffer.Length then
144143
let repl = Array.zeroCreate (lexbuf.BufferScanPos + n)
145-
Array.blit buffer bufferScanStart repl bufferScanStart bufferScanLength;
144+
Array.blit buffer bufferScanStart repl bufferScanStart bufferScanLength
146145
buffer <- repl
147146

148147

@@ -151,8 +150,8 @@ namespace Internal.Utilities.Text.Lexing
151150
let extension= Array.zeroCreate 4096
152151
let filler (lexBuffer: LexBuffer<'Char>) =
153152
let n = f (extension,0,extension.Length)
154-
lexBuffer.EnsureBufferSize n;
155-
Array.blit extension 0 lexBuffer.Buffer lexBuffer.BufferScanPos n;
153+
lexBuffer.EnsureBufferSize n
154+
Array.blit extension 0 lexBuffer.Buffer lexBuffer.BufferScanPos n
156155
lexBuffer.BufferMaxScanLength <- lexBuffer.BufferScanLength + n
157156
new LexBuffer<'Char>(filler)
158157

src/utils/prim-parsing.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ type Stack<'a>(n) =
8383
let oldSize = contents.Length
8484
if newSize > oldSize then
8585
let old = contents
86-
contents <- Array.zeroCreate (max newSize (oldSize * 2));
87-
Array.blit old 0 contents 0 count;
86+
contents <- Array.zeroCreate (max newSize (oldSize * 2))
87+
Array.blit old 0 contents 0 count
8888

8989
member buf.Count = count
9090
member buf.Pop() = count <- count - 1

0 commit comments

Comments
 (0)