Skip to content

Commit

Permalink
Using default constructor for ResizeArray
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Paul Westcott committed Aug 12, 2015
1 parent 3796a55 commit 037a5e1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/fsharp/FSharp.Core/array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,6 @@ namespace Microsoft.FSharp.Collections
let inline groupByImpl (comparer:IEqualityComparer<'SafeKey>) (keyf:'T->'SafeKey) (getKey:'SafeKey->'Key) (array: 'T[]) =
let dict = Dictionary<_,ResizeArray<_>> comparer

// Previously this was 1, but I think this is rather stingy, considering that we are alreadying paying
// for at least a key, the ResizeArray reference, which includes an array reference, an Entry in the
// Dictionary, plus any empty space in the Dictionary of unfilled hash buckets. Having it larger means
// that we won't be having as many re-allocations. The ResizeArray is destroyed at the end anyway.
let initialBucketSize = 4

// Build the groupings
for i = 0 to (array.Length - 1) do
let v = array.[i]
Expand All @@ -440,7 +434,7 @@ namespace Microsoft.FSharp.Collections
if dict.TryGetValue(safeKey, &prev) then
prev.Add v
else
let prev = ResizeArray initialBucketSize
let prev = ResizeArray ()
dict.[safeKey] <- prev
prev.Add v

Expand Down
8 changes: 1 addition & 7 deletions src/fsharp/FSharp.Core/list.fs
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,6 @@ namespace Microsoft.FSharp.Collections
let inline groupByImpl (comparer:IEqualityComparer<'SafeKey>) (keyf:'T->'SafeKey) (getKey:'SafeKey->'Key) (list: 'T list) =
let dict = Dictionary<_,ResizeArray<_>> comparer

// Previously this was 1, but I think this is rather stingy, considering that we are alreadying paying
// for at least a key, the ResizeArray reference, which includes an array reference, an Entry in the
// Dictionary, plus any empty space in the Dictionary of unfilled hash buckets. Having it larger means
// that we won't be having as many re-allocations. The ResizeArray is destroyed at the end anyway.
let initialBucketSize = 4

// Build the groupings
let rec loop list =
match list with
Expand All @@ -467,7 +461,7 @@ namespace Microsoft.FSharp.Collections
if dict.TryGetValue(safeKey, &prev) then
prev.Add v
else
let prev = ResizeArray initialBucketSize
let prev = ResizeArray ()
dict.[safeKey] <- prev
prev.Add v
loop t
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/FSharp.Core/seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ namespace Microsoft.FSharp.Collections
match dict.TryGetValue (safeKey, &prev) with
| true -> prev.Add v
| false ->
let prev = ResizeArray minimumBucketSize
let prev = ResizeArray ()
dict.[safeKey] <- prev
prev.Add v)

Expand Down

0 comments on commit 037a5e1

Please sign in to comment.