Skip to content

Commit 329da81

Browse files
forkibaronfel
authored andcommitted
Do not convert back and forth from list (#8262)
* Do not convert back and forth from list * Use a simple for loop in replicate * Put wildcard back
1 parent b77231c commit 329da81

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/fsharp/FSharp.Core/list.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ namespace Microsoft.FSharp.Collections
171171
[<CompiledName("Initialize")>]
172172
let init length initializer = Microsoft.FSharp.Primitives.Basics.List.init length initializer
173173

174-
let rec initConstAcc n x acc =
175-
if n <= 0 then acc else initConstAcc (n-1) x (x :: acc)
176-
177174
[<CompiledName("Replicate")>]
178175
let replicate count initial =
179176
if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
180-
initConstAcc count initial []
177+
let mutable result = []
178+
for i in 0..count-1 do
179+
result <- initial :: result
180+
result
181181

182182
[<CompiledName("Iterate2")>]
183183
let iter2 action list1 list2 =

src/fsharp/FSharp.Core/local.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ open System.Collections.Generic
8383

8484
module internal List =
8585

86-
let arrayZeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #)
86+
let inline arrayZeroCreate (n:int) = (# "newarr !0" type ('T) n : 'T array #)
8787

8888
[<SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")>]
8989
let nonempty x = match x with [] -> false | _ -> true

src/fsharp/TypeChecker.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5482,7 +5482,7 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p
54825482
| [SynPatErrorSkip(SynPat.Tuple (false, args, _)) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Tuple (false, args, _)), _))] when numArgTys > 1 -> args
54835483

54845484
// note: we allow both 'C _' and 'C (_)' regardless of number of argument of the pattern
5485-
| [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> Array.toList (Array.create numArgTys e)
5485+
| [SynPatErrorSkip(SynPat.Wild _ as e) | SynPatErrorSkip(SynPat.Paren(SynPatErrorSkip(SynPat.Wild _ as e), _))] -> List.replicate numArgTys e
54865486
| [arg] -> [arg]
54875487
| _ when numArgTys = 0 -> error(Error(FSComp.SR.tcUnionCaseDoesNotTakeArguments(), m))
54885488
| _ when numArgTys = 1 -> error(Error(FSComp.SR.tcUnionCaseRequiresOneArgument(), m))

0 commit comments

Comments
 (0)