Skip to content

Commit 037a5e1

Browse files
author
Paul Westcott
committed
Using default constructor for ResizeArray
Initially this had been set to 1, I had changed it to 4, but after discussion it was decided that the default is probably the correct choice. As per #549 (comment)
1 parent 3796a55 commit 037a5e1

File tree

3 files changed

+3
-15
lines changed

3 files changed

+3
-15
lines changed

src/fsharp/FSharp.Core/array.fs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,6 @@ namespace Microsoft.FSharp.Collections
426426
let inline groupByImpl (comparer:IEqualityComparer<'SafeKey>) (keyf:'T->'SafeKey) (getKey:'SafeKey->'Key) (array: 'T[]) =
427427
let dict = Dictionary<_,ResizeArray<_>> comparer
428428

429-
// Previously this was 1, but I think this is rather stingy, considering that we are alreadying paying
430-
// for at least a key, the ResizeArray reference, which includes an array reference, an Entry in the
431-
// Dictionary, plus any empty space in the Dictionary of unfilled hash buckets. Having it larger means
432-
// that we won't be having as many re-allocations. The ResizeArray is destroyed at the end anyway.
433-
let initialBucketSize = 4
434-
435429
// Build the groupings
436430
for i = 0 to (array.Length - 1) do
437431
let v = array.[i]
@@ -440,7 +434,7 @@ namespace Microsoft.FSharp.Collections
440434
if dict.TryGetValue(safeKey, &prev) then
441435
prev.Add v
442436
else
443-
let prev = ResizeArray initialBucketSize
437+
let prev = ResizeArray ()
444438
dict.[safeKey] <- prev
445439
prev.Add v
446440

src/fsharp/FSharp.Core/list.fs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,6 @@ namespace Microsoft.FSharp.Collections
452452
let inline groupByImpl (comparer:IEqualityComparer<'SafeKey>) (keyf:'T->'SafeKey) (getKey:'SafeKey->'Key) (list: 'T list) =
453453
let dict = Dictionary<_,ResizeArray<_>> comparer
454454

455-
// Previously this was 1, but I think this is rather stingy, considering that we are alreadying paying
456-
// for at least a key, the ResizeArray reference, which includes an array reference, an Entry in the
457-
// Dictionary, plus any empty space in the Dictionary of unfilled hash buckets. Having it larger means
458-
// that we won't be having as many re-allocations. The ResizeArray is destroyed at the end anyway.
459-
let initialBucketSize = 4
460-
461455
// Build the groupings
462456
let rec loop list =
463457
match list with
@@ -467,7 +461,7 @@ namespace Microsoft.FSharp.Collections
467461
if dict.TryGetValue(safeKey, &prev) then
468462
prev.Add v
469463
else
470-
let prev = ResizeArray initialBucketSize
464+
let prev = ResizeArray ()
471465
dict.[safeKey] <- prev
472466
prev.Add v
473467
loop t

src/fsharp/FSharp.Core/seq.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ namespace Microsoft.FSharp.Collections
14611461
match dict.TryGetValue (safeKey, &prev) with
14621462
| true -> prev.Add v
14631463
| false ->
1464-
let prev = ResizeArray minimumBucketSize
1464+
let prev = ResizeArray ()
14651465
dict.[safeKey] <- prev
14661466
prev.Add v)
14671467

0 commit comments

Comments
 (0)